Project

General

Profile

Feature #252

Template parser - if statements & for loops

Added by Jacko Hoogeveen over 13 years ago. Updated almost 13 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Elmer de Looff
Category:
TemplateParser
Target version:
-
Start date:
2011-06-29
Due date:
% Done:

100%

Estimated time:
Spent time:

Description

If statements and for loops in the templates.

Example if (jango style):

<body>
{% if var1 %}
  <div>
    Lorem Ipsum
  </div>
{% elseif var2 %}
  <div>
    Lorem Ipsum
  </div>
{% endif %}
</body>

Example for (jango style):

<ul>
{% for athlete in athlete_list %}
  <li>{{ athlete.name }}</li>
{% endfor %}
</ul>


Related issues

Related to µWeb - Feature #61: Template parser - default valuesClosed2011-05-02

Associated revisions

Revision 118:6df048aa7fcd (diff)
Added by Elmer de Looff almost 13 years ago

Added first testcase checking the behaviour of FOR-loops: Test succeeds! Declaring v1.0 of templateparser. Lots of code cleanup still needed before we can merge this, but this resolves #252.

Revision 157:83666f9b5d14 (diff)
Added by Elmer de Looff almost 13 years ago

Added {{ if }} statements to the templateparser. This allows richer expressions in templates. if, elif and else are properly supported. This completely resolves #252 and makes obsolete issue #61.

History

#1 Updated by Jan Klopper over 13 years ago

Im still not sure If we'd want this.

Yes, it would make the pagemakers less intricate. But meh, if's in templates just make it possible to have too much logic in there.

Loops are less of a problem imho, however There needs to be a pretty good and clean syntax.

#2 Updated by Elmer de Looff over 13 years ago

This would upgrade the 'dumb template' to an actual View (as in, MVC). I'm not sure this is a bad idea, actually, I think it's a good idea. Currently we have a huge amalgamation of little template snippets that aren't really super useful imo.

For loops are a 'requirement' for the future I would say. I've less strong feelings about if/else structures, but it might make sense to toss out defaults in favor of them.

#3 Updated by Elmer de Looff about 13 years ago

  • Category set to TemplateParser

#4 Updated by Elmer de Looff almost 13 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 70

For-loops have been added to the templateparser in a separate branch of the Underdark repository. The merge is pending more extensive testing and a good bit of code-cleanup and thorough documentation.

Example template:

<html>
  <body>
    <ul>
    {{ for person in [names] }}
      <li>Hello [person]</li>
    {{ endfor }}
    </ul>
  </body>
</html>

When this template is parsed with names=('Tom', 'Dick', 'Harry'), the output will be (barring copious whitespace differences):

<html>
  <body>
    <ul>
      <li>Hello Tom</li>
      <li>Hello Dick</li>
      <li>Hello Harry</li>
    </ul>
  </body>
</html>

#5 Updated by Elmer de Looff almost 13 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 70 to 100

All relevant tests and documentation has been added, and the development branch has been merged in to the production branch.

#6 Updated by Elmer de Looff almost 13 years ago

{{ if }} statement now included in templateparser. For a minor example, refer to issue #61.

Also available in: Atom PDF