Django translations inside included HTML template - html

I am including a file in a Django webpage using this:
{% include 'footer.html' %}
This included HTML file contains trans tags, which are not being translated. In fact, Django returns a TemplateSyntaxError:
Invalid block tag: 'trans'
I know that the include tag does not process the included file. I've seen other questions ask about overriding blocks in included files, to which the answers mentioned that this is not possible in Django. I presume this is the same problem.
Is there a way to force Django to process included files, or some other tag that achieves this? Or maybe Python code, as a last resort?
Important note: I cannot simply add the footer in a base file and extend from this base, because I already have a base, which is actually the one trying to include footer.html (I have several base templates for different sub-sites, but all of which should use the same footer).

inside footer.html you need to load i18n
{% load i18n %}
quote from the docs:
As with all template tags, this tag needs to be loaded in all
templates which use translations, even those templates that extend
from other templates which have already loaded the i18n tag.

Related

Include and Static statements are not being recognized with GitPages

I am new to GitPages and have successfully built and ran my page. However, the {% include %} and {% static %} methods in my index.html aren't being registered. As you can see here. Additionally, my two static files referenced in this file (circleselfie.png and home.css) have weird characters in their static paths when inspecting the page. Here is my project: https://github.com/jishli113/JSite/tree/master. What is causing this?
Gitpages, unfortunately, doesn't support a django backend. It's primarily for static/clientside sites, so your templates are just being treated as normal HTML.

Jekyll: parse pages without front matter

As far as I gather, Jekyll parses an included page through the templating stage if and only if it finds a YAML header / front matter. Otherwise it just copies it. Is there a way to force Jekyll to parse an included file without a front matter?
The rule of thumb is that Jekyll will not parse files without front matter.
However... there is a work-around. You can create an index.html file in the _includes directory without front matter. The Liquid in this file will be interpreted by Jekyll. You can render this include anywhere using:
{% include index.html %}
This solution is perfect for rendering HTML pages within a Jekyll context (without having the front matter requirement), especially when you want to reuse them. This could be useful for rendering a preview AND showing the code in a code block on another page. The include could be written in a layout file or in an index.md file.
Note that the included filename can be a variable (https://jekyllrb.com/docs/includes/):
{% if page.my_variable %}
{% include {{ page.my_variable }} %}
{% endif %}
Also note that if you want to show Liquid examples in this code, you should use:
{% raw %} ... Liquid example ... {% endraw %}
If you want a solution work-around for your specific situation, you should share your repository and explain your use case.

Directly copy some Pelican templates to output folder

I have a few new templates in my pelican theme (a growing number of them, really). They are html files that hold simple web maps. I use these by {% include %}ing them after the content of a blog post. I place the path to the webmap1.html template in the markdown metadata, and then in article.html I {% include %} the web map html at the bottom of the file.
Thing is, I really would like to have these html files available as standalone html in my output as well. Initially I thought I'd be able to do this by placing webmap1.html in my content directory and using STATIC_PATHS to copy it to the output. However, I was unable to get the include statement to find an html file that is not within the theme/templates directory.
I also found that adding /theme/templates/maps or ../theme/templates/maps to STATIC_PATHS didn't work.
Of course, one way to do this would be to include identical files in both the content directory and the template directory, but that seems sloppy. Alternatively, I could add a command to pelican to copy the files from one place to another before the generation happens. Looking for an alternative solution though.
Thanks!
Well, turns out I was outsmarting myself with this. All I needed to do was use the
DIRECT_TEMPLATES = [
r'maps/webmap1',
]
setting in pelicanconf.py. That way, I can {% include 'maps/webmap1.html' %} in a separate template, and also write it to its own standalone location in the output directory.

Make kramdown's ALDs available on entire Jekyll site

I'm using Jekyll to make a site that makes frequent use of kramdown's attribute list definitions. However the only way I can make this work right now is to include all of the definitions in every page e.g.
{:def1: ...}
{:def2: ...}
{:def3: ...}
This seems really smelly to me since if I want to change a definition, I need to do so in every single page. Ugh.
Is it possible to put these definitions somewhere where they will be included in every page? I tried putting them in a layout but it seems that Jekyll won't parse markdown in layouts.
I'm also open to alternatives to ALDs if this is not the right way to go about things.
If you want to add definitions to your posts, you can also create an .md file in your _includes folder with definitions like:
*[def1]: ...
*[def2]: ...
And then you can add this file to every post using {% include definitions.md %}.
It shouldn't be in the _layouts folder. Try keeping it in the _includes folder and then include it with this tag {% include definitions.html %}

Jekyll Slideshow Side-By-Side With Regular Posts

I am looking to make a slideshow using Jekyll but would like to have the slideshow be a single post alongside regular blog posts. I found a few Jekyll themed slideshows using impress.js here and here, but in the examples for both they are relying on a single static html file that simply pulls all of the posts from the _posts folder. I can filter out the non-slideshow posts by class, but that would not solve the situation of having two slideshows as slides from both would be pulled in.
Is there a way of passing information from the slide post (eg a "Title") that can be read in the static html file to determine which posts belong to this slideshow? Alternatively, is there a different way to go about doing this?
Old question but I have been diggin into it anyway
Hekyll is a very nice tool
To prevent a post from showing up in a presentation, you can mark it with a specific tag in the front matter, say not_a_slide: true
Then edit the layout perso.html here at the root of the project and {% unless page.not_a_slide %} before {% include slide.html %} and {% endunless %} after.