lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi, I've been working on a template library written in lua. Probably fills a role similar to Cosmo. This is called "tier", has django style extends, block/endblock (A template inheritance mechanism) and include, plus other important differences.

Please take a look at it and tell me what you think!

View the example here:

The template source of the above example is here:

The lua source that calls the template is here:

Github repository:

lua source:
  require 'tier.template'
  local a = tier.Template.load("templates/example2.html")
  print(a:render{planet="Earth", 
                 answer=function() return "42" end, 
                 name="example2.html",
                 replaced="--replaced by a block--"})

template source without the commentary:
{% extends 'example.html' %}

{% block title %}The Solar System{% endblock %}
{% block content %}
  {% include 'name.html' %}
  <a href="">Template Source</a>
  <h1>Planetary Intranet</h1>
  <h2>Hello there, visitor from planet {{ planet }}</h2>
  <h3>Your planet's name repeated three times:</h3> 
  <ul>{{ ("<li>"..planet.."</li>"):rep(3) }}</ul>
  <h3> The number of letters in your planet's name: {{ #planet }} </h3>
  <h2>A three by three grid of values:</h2>
  <table>
  {% for x=1, 3, 1 do %}
      <tr>
      {% for y=1, 3, 1 do %}
          <td>(x={{x}}, y={{y}})</td>
      {% end %}
      </tr>
  {% end %}
  </table>
  <h5>All template variables are global to all templates being rendered. i.e. this template, the parent template and the parent of that template, and any templates that were included anywhere by any of those templates. </h5>
  <h5>Also, block names and argument names are in the same namespace; You can replace a block of a template the same way you set variables of a template. See lua source at <a href="">top</a>.</h5>
  {% block replaced %}gibberish{% endblock %}
{% endblock %}

Comments very welcome!

Eric