Hi all
    I'm migrating a small static website I developed with Jinja, to
Jinja2. I have a base template file, and a file for each page,
together with a python script which simply loads each file and renders
it to html.

I have some common files which I import & include. I'm hitting an
error which I don't understand.

without putting up the whole scheme, I have a base file like:

#------- base.tmpl
{% import "include/macros.incl" as helpers %}
{% import "include/quotes.incl" as quotes %}

{% block content %}
{% endblock %}


#---------------

and an inherited file like

# --------------- index.tmpl
{% extends "base.tmpl" %}

{% block content %}
{% include "include/inc1.incl" %}
{% endblock %}

#-----------------------

now the included file inc1.incl attempts to use macros previously
imported from the 'macros' file:

#---------------- macros.html
{% macro shorthline() %}
*** definition here ***
{% endmacro %}


# ------------ include/inc1.incl

{{ helpers.shorthline() }}

#-------------------

When I attempt to render this I get an error like:

  File "/usr/lib/python2.4/site-packages/Jinja2-2.1dev_20081012-py2.4-
linux-i686.egg/jinja2/environment.py", line 332, in getattr
    return getattr(obj, attribute)
  File "/usr/lib/python2.4/site-packages/Jinja2-2.1dev_20081012-py2.4-
linux-i686.egg/jinja2/runtime.py", line 403, in
_fail_with_undefined_error
    raise self._undefined_exception(hint)
jinja2.exceptions.UndefinedError: 'helpers' is undefined


Strangely (to me) I can prevent this by invoking the macro in the
higher template, which makes me think that is something to do with
caching:

# --------------- index.tmpl ------ this one works
{% extends "base.tmpl" %}


{% block content %}

{{ helpers.shorthline() }}

{% include "include/inc1.incl" %}
{% endblock %}

#-----------------------

however it doesn't seem to be solved by the 'with context' feature.

I'm sure I'm missing something simple here - can anyone help me
realise what it is?

    Thanks
    J^n




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pocoo-libs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pocoo-libs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to