Having learned how to make timestamps again, I'd wound up with quite a lot of lines of template that didn't really do anything too, too awe inspiring. In short, I needed a twelve line block of kml to display a single digit of a time or a date. I decided the spiffy thing to do would be to move this kml template into a file that I'd include from the base kml map jinja template. It was more difficult than I originally thought it would be.
Turns out that simply adding the include line did not do the trick. I got back the error message:
no loader for this environment specified
A little bit of research led to a solution. Jinja template objects in Python needs to have an Environment that is properly setup if you plan to include other templates from inside a template. That led to this line
tmpl = Template(f.read())
changing to this line
tmpl = Environment(loader=FileSystemLoader("./plugins/templates")).from_string(f.read())
At which point the template was located.
Then, it became apparent that template includes are not simple text substitutions when I got back the error:
jinja2.exceptions.UndefinedError: 'loop' is undefined
when I referenced the loop variable from within the template. I fixed this by moving the entire loop into the template, so that my included datetime template wasn't included in a loop, but contained a loop.
After that, I worked with the character spacing and jinja variables a bit ala
{% set offset = 0.03 %}
{% set char_space = 0.03 %}
{% set block_space = 0.0365 %}
{% set section_space = 0.07 %}
Comments
Post a Comment
Please leave your comments on this topic: