[plug] Jinja/LaTeX child templates (this time on github instead of attachment)
Kirk Turner
gameldar at gmail.com
Tue Jan 28 11:02:58 AWST 2020
Hi Chris,
I'll preface this by a "I'm not a jinja2 expert" (I've mostly used it for
ansible templates) - but having a second pair of eyes on it helps!
The problem is two fold:
1. In your Environment creation you've changed the markers for the start
(and end blocks) from {% to \BLOCK{ - but then proceeded to use the old
markers in some places - so in your child template you'll need to have:
\BLOCK{ extends "jinja-test.template" }
\BLOCK{ block content }
My string: \VAR{my_string}
Value from the list: \VAR{my_list[3]}
Loop through the list:
\begin{itemize}
\item
\BLOCK{ for n in my_list }
\VAR{n}
\BLOCK{ endfor }
\end{itemize}
\BLOCK{ endblock }
Note the for loop also seems to be missing the endfor so I've also adjusted
that.
Likewise there are still some usages of the {% block declarations in the
jinja-test.templates file too.
2. I'm guessing you'd figure this out given the commented out lines in the
test case - but you need to load and render the 'child' template (so the
test2.template) - it then loads the base or parent template and replaces
the appropriate parts in there.
Thanks,
Kirk
On Mon, 27 Jan 2020 at 15:49, Chris Caston <chris at caston.id.au> wrote:
> I have been trying to figure out how to use child templates (amongst other
> things you will see in the git repository hosted python and LaTeX template
> code) in Jinja when working with LaTeX. This has been tricky as most of the
> pages I can find are specific to HTML.
>
> I am trying to render the child template (test2.template) in
> jinja-test.template where I have written:
>
> \section{\VAR{section8}}
> {% block content %}{% endblock %}
>
> I have probably missed something very simple but looking at so much code
> from so many
> places is getting me confused.
>
> Here is my code so far and the links to resources I am been trying to
> learn from:
>
> https://jinja.palletsprojects.com/en/2.10.x/templates/#base-template
> https://realpython.com/primer-on-jinja-templating/
>
> http://akuederle.com/Automatization-with-Latex-and-Python-2
>
> http://eosrei.net/articles/2015/11/latex-templates-python-and-jinja2-generate-pdfs
>
> Here is the code on github.
> https://github.com/warmheartcoin/jinjalatex.git
> Thank you in advance for your help.
>
> best regards,
>
> Chris Caston
> _______________________________________________
> PLUG discussion list: plug at plug.org.au
> http://lists.plug.org.au/mailman/listinfo/plug
> Committee e-mail: committee at plug.org.au
> PLUG Membership: http://www.plug.org.au/membership
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plug.org.au/pipermail/plug/attachments/20200128/d6b499f5/attachment.html>
More information about the plug
mailing list