Edgewall Software

Opened 17 years ago

Closed 17 years ago

#194 closed defect (fixed)

TextTemplate - python expressions in includes fail

Reported by: oliver.cope@… Owned by: cmlenz
Priority: major Milestone: 0.5
Component: Template processing Version: devel
Keywords: Cc:

Description

The documentation for TextTemplate says:

Just like other directives, the argument to the include directive accepts any Python expression, so the path to the included template can be determined dynamically...

But it fails when I try this.

Test case:

def test_include_expr(self):
     file1 = open(os.path.join(self.dirname, 'tmpl1.txt'), 'w')
     try:
         file1.write("Included")
     finally:
         file1.close()
 
     file2 = open(os.path.join(self.dirname, 'tmpl2.txt'), 'w')
     try:
         file2.write("""----- Included data below this line -----
{% include '%s.txt' % ('tmpl1',) %}
----- Included data above this line -----""")
     finally:
         file2.close()

     loader = TemplateLoader([self.dirname])
     tmpl = loader.load('tmpl2.txt', cls=NewTextTemplate)
     self.assertEqual("""----- Included data below this line -----
Included
----- Included data above this line -----""", tmpl.generate().render())

Change History (1)

comment:1 Changed 17 years ago by cmlenz

  • Component changed from General to Template processing
  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [809]. Note though that you'll need to use proper expression syntax, contrary to what the docs previously stated, i.e.:

{% include ${'%s.txt' % filename} %}
Note: See TracTickets for help on using tickets.