Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
tier/templates/example2.html
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
113 lines (105 sloc)
2.75 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% extends 'example.html' %} | |
| {% block title %}The Solar System{% endblock %} | |
| {% block content %} | |
| <pre> | |
| -- 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--"}) | |
| </pre> | |
| {% include 'name.html' %} | |
| <p> | |
| <div class="src"> | |
| <span>{%</span> | |
| include 'name.html' | |
| <span>%}</span> | |
| </div> | |
| <p> | |
| <a href="templates/example2.txt">Template Source</a> | |
| <h1>Planetary Intranet</h1> | |
| <h2>Hello there, visitor from planet {{ planet }}</h2> | |
| <div class="src"> | |
| <span>{{</span> | |
| planet | |
| <span>}}</span> | |
| </div> | |
| <h3>Your planet's name repeated three times:</h3> | |
| <ul>{{ ("<li>"..planet.."</li>"):rep(3) }}</ul> | |
| <div class="src"> | |
| <span>{{</span> | |
| ("<li>"..planet.."</li>"):rep(3) | |
| <span>}}</span> | |
| </div> | |
| <h3> The number of letters in your planet's name: {{ #planet }} </h3> | |
| <div class="src"> | |
| <span>{{</span> | |
| #planet | |
| <span>}}</span> | |
| </div> | |
| <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> | |
| <p> | |
| <div class="src"> | |
| <span>{%</span> | |
| for x=1, 3, 1 do | |
| <span>%}</span> | |
| <br><tr><br> | |
| <span>{{(" "):rep(4)}}{%</span> | |
| for y=1, 3, 1 do | |
| <span>%}</span> | |
| <br>{{(" "):rep(8)}}<td>(x= | |
| <span>{{</span> | |
| x | |
| <span>}}</span>, y= | |
| <span>{{</span> | |
| y | |
| <span>}}</span> | |
| )</td> | |
| <br> | |
| <span>{{(" "):rep(4)}}{%</span> | |
| end | |
| <span>%}</span> | |
| <br> | |
| </tr> | |
| <br> | |
| <span>{%</span> | |
| end | |
| <span>%}</span> | |
| </div> | |
| <h3>After the nested for loop:</h3> | |
| <h4>The value of x is now {{ x }} </h4> | |
| <div class="src"> | |
| {{ tier.escape_html [[{{ x }}]] }} | |
| </div> | |
| <h4>The value of y is now {{ y }} </h4> | |
| <div class="src"> | |
| {{ tier.escape_html [[{{ y }}]] }} | |
| </div> | |
| <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">top</a>.</h5> | |
| {% block replaced %}gibberish{% endblock %} | |
| <p> | |
| <div class="src"> | |
| {{ tier.escape_html [[{% block replaced %}gibberish{% endblock %}]] }} | |
| </div> | |
| <h3> Time taken to generate this template:</h3> | |
| <pre> | |
| real 0m0.020s | |
| user 0m0.015s | |
| sys 0m0.003s | |
| </pre> | |
| {% endblock %} | |
| {% block footer %} | |
| <div class="space"></div> | |
| {% endblock %} |