On Sun, Oct 24, 2010 at 11:47 PM, Joakim Hove <[email protected]> wrote:
> Hello,
>
> to assist those responsible for the content of "my" site I would like
> to embed the file-system path to the template in the rendered
> template, so that when they find something they are dissatisfied with
> on a page they can do "View Source" and easily identify the correct
> template to update.
>
> I.e. I would like to embed something like this at the top of all the
> templates:
>
> <!-- This template is located in: {{ template_path }} -->
>
> Is this possible?

Not without jumping through some hoops. The template currently being
rendered isn't exposed as a template context variable.

There are a couple of reasons for this.

Firstly, there's the issue of interpretation; as soon as you start
using {% extends %} or {% include %} tags, which any moderately
complex template will do, there are multiple template files involved.
It's not much good just printing the path to one template file when 6
files are actually involved in the rendering process.

Secondly -- you can't really answer the question of which templates
were used to render a page until all the page is rendered, by which
time, it's too late to insert content into the page.

However, if you just want to know the top-level template that started
the rendering process, you could obtain this by writing a custom
render_to_template() shortcut that inserts the loaded template name
into the context.

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" 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/django-users?hl=en.

Reply via email to