[SOLVED] Issues with implementing templates

Been trying to implement custom templates on my gitea installation for a while. I am using the docker implementation.

I have checked the gitea documentation on templating and configuration, but the documentation is honestly pretty vague.

The last indication from @lafriks suggests the following:

As for custom folder it specified in GITEA_CUSTOM variable or by default it is $GITEA_WORK_DIR/custom

Custom templates need to be placed in $GITEA_CUSTOM/custom/templates/custom/ directory

However, there is no information under the documentation as to what category the GITEA_CUSTOM variable goes under. I added it under the [ui] and then at the top (no category), to no avail.

The desired value for GITEA_CUSTOM is /data/gitea/custom (in docker, I am assuming the $GITEA_WORK_DIR resolves to /data/gitea, but even this I don’t know for sure. The app.ini file says that APP_DATA_PATH resolves /data/gitea).

Interestingly enough, printenv inside the container has no mention of GITEA_WORK_DIR, but it shows GITEA_CUSTOM as /data/gitea

As such, I have put my template files in the following places, hoping that at least one of the locations would get picked up:

  • /data/gitea/custom/templates/custom/header.tmpl
  • /data/gitea/custom/templates/header.tmpl
  • /data/gitea/custom/header.tmpl
  • /data/gitea/templates/custom/header.tmpl
  • /data/gitea/templates/header.tmpl

All of the files have a single value: <!-- this is a test to see if it is picked up by gitea -->.

I do take care of taking down the docker container and restarting it (something that I have seen mentioned).

However, when looking at the html source of the gitea app, the code introduced in my template is nowhere to be found. I have cleared browser cache, logged out, logged back in, to no avail.

Thanks in advance to anyone who has made this work and has some info on how this is supposed to go.

1 Like

Update: I realized the GITEA_CUSTOM variable is not an app.ini variable, but one that is specified at the ENV level (at least in docker), so I removed it from app.ini. The default GITEA_CUSTOM per printenv resolves to /data/gitea. But knowing this for sure still does not solve my issue, because I do have a template file in /data/gitea/templates/custom/header.tmpl which is not getting picked up.

1 Like

It turns out, for anyone who experiences this: apparently the templating engine strips out all html comments from the code. This is why I could not see my comment being picked up. In my case, with GITEA_CUSTOM being mapped to /data/gitea, the full, correct path to my template file was /data/gitea/templates/custom/header.tmpl.

With this information I understand better and can move my files to a more structured location. Hope this helps anyone. If in doubt, the printenv command will tell you exactly where GITEA_CUSTOM is pointing, even inside a docker container (have to use docker exec).

Thanks to @lafriks for the help.

1 Like

Further question: So, now that I have been able to identify where my header.tmpl file should be located, I am now trying to figure out how I call out my custom css files, specifically what path to put in my <link> tags, and really for any additional assets I want to have. I am pretty positive there is no info on this on the documentation ({{AppSubUrl}} doesn’t seem to work, it returns an empty value).

Based on my particular environment I have tried /data/gitea/templates/custom/myfile.css, but the link returns a 404 response. What path do I need to use?


Resolution: After looking closer into what the documentation says (actually applied to different matter), I realized I needed to have a public folder where my assets are to be found. I created this folder under my GITEA_CUSTOM/public, and placed my assets there. After doing this, gitea picked up my files and I am now good to go. All I can say is, goodness gracious. Hopefully someone finds this helpful, which is why I left the whole process.

1 Like

Looking nice :smile:, more GitHub-like…Heh.

1 Like