Menu

#6 include/extend tags are relative from the current template

Core
open
Maluku
7
2010-09-17
2010-09-06
Ben
No

I found this bug by using the extend tag, but assuming it also effects include tag.

When passing the file path to the extend tag, the path is always relative to the template that is currently being processed. This is problematic when rendering templates within sub directories of the template directory.

An example
Consider the following directory structure:
- Templates
|-> layouts
| main.html
|-> blog
| entries.html
`> home.html

When using Dotiac to parse home.html, home.html could use the extends tag to extend layouts/main.html:

{% extends "layouts/main.html" %}

However if you try and do this within blog/entries.html, it will not work because it will in fact try to use blog/layouts/main.html, which does not exist. In django the tags extend and include lookup the paths that they are passed relative to the template directories configured in TEMPLATE_DIRS. This list of directories could be @Dotiac::DTL::TEMPLATE_DIRS, since this is already used when using Dotiac in a django fashion (exported Template and Context).

I have included a svn diff of the changes I have made locally and the test I wrote for it in the hope it helps.

Some background:
I discovered this bug while trying to write a Dotiac renderer for Mojolicious. Mojolicious uses a single directory to store templates, which are typically organised in subfolders for each controller, which inherit from other templates. Currently this is (the simplified) version of that code:

@Dotiac::DTL::TEMPLATE_DIRS = $config{template_paths};
my $template = Dotiac::DTL::Template($template_name);
my $context = Dotiac::DTL::Context({%{$c->stash}, c => $c, h => $helper});
$$output = $template->render($context);

Discussion

  • Maluku

    Maluku - 2010-09-17

    I did not think of that...
    Maybe I can find a good solution to account for all subfolder related woes. Django's solution sounds very good to me.

     
  • Maluku

    Maluku - 2010-09-17
    • priority: 5 --> 7
    • assigned_to: nobody --> maluku
     
  • Ben

    Ben - 2010-09-17

    Local copy diff used as workaround

     

Log in to post a comment.

Auth0 Logo