The Pongo2 Template Engine
Pongo2 is the successor of pongo, a Django-syntax like templating-language.
Dependencies
Install/update using go get
(no dependencies required by pongo2):
go get -u github.com/flosch/pongo2
Setup
Pongo2 template files should start with a shebang
(#!
) on the first line. Alternatively, you may append the suffix *.pongo2.html
to template file names.
Control case sensitivity by setting pongo2.tempate.caseinsensitive=false
in app.conf
to:
true
(default) case insensitivefalse
compiled using lower case (default)
Currently, the Pongo2 template engine can’t access revel.TemplateFuncs
(PR welcome). These functions are built-in:
- field
- radio
- option
- url
- checkbox
- append
Examples
Try pongo2 out in the pongo2 playground.
{%append "moreStyles" "ui-lightness/jquery-ui-1.7.2.custom.css"%}
{%append "moreScripts" "js/jquery-ui-1.7.2.custom.min.js"%}
{% include "header.html" %}
<h1>Book hotel</h1>
<form method="POST" action="{%url "Hotels.Book" hotel.HotelId%}">
<p>
<strong>Name:</strong> {{hotel.Name}}
</p>
<p>
<strong>Address:</strong> {{hotel.Address}}
</p>
<p>
<strong>City:</strong> {{hotel.City}}
</p>
<p>
<strong>State:</strong> {{hotel.State}}
</p>
<p>
<strong>Zip:</strong> {{hotel.Zip}}
</p>
<p>
<strong>Country:</strong> {{hotel.Country}}
</p>
<p>
<strong>Nightly rate:</strong> {{hotel.Price}}
</p>
{%with field = "booking.CheckInDate"|field %}
<p class="{{field.ErrorClass}}">
<strong>Check In Date:</strong>
<input type="text" size="10" name="{{field.Name}}" class="datepicker" value="{{field.Flash}}">
* <span class="error">{{field.Error}}</span>
</p>
{% endwith %}
{%with field = "booking.CheckOutDate"|field %}
<p class="{{field.ErrorClass}}">
<strong>Check Out Date:</strong>
<input type="text" size="10" name="{{field.Name}}" class="datepicker" value="{{field.Flash}}">
* <span class="error">{{field.Error}}</span>
</p>
{% endwith %}
<p>
<strong>Room preference:</strong>
{%with field = "booking.Beds"|field %}
<select name="{{field.Name}}">
{%option field "1" "One king-size bed"%}
{%option field "2" "Two double beds"%}
{%option field "3" "Three beds"%}
</select>
{% endwith %}
</p>
<p>
<strong>Smoking preference:</strong>
{%with field = "booking.Smoking"|field %}
{%radio field "true"%} Smoking
{%radio field "false"%} Non smoking
{% endwith %}
</p>
{%with field = "booking.CardNumber"|field %}
<p class="{{field.ErrorClass}}">
<strong>Credit Card #:</strong>
<input type="text" name="{{field.Name}}" size="16" value="{{field.Flash}}">
* <span class="error">{{field.Error}}</span>
</p>
{% endwith %}
{%with field = "booking.NameOnCard"|field %}
<p class="{{field.ErrorClass}}">
<strong>Credit Card Name:</strong>
<input type="text" name="{{field.Name}}" size="16" value="{{field.Flash}}">
* <span class="error">{{field.Error}}</span>
</p>
{% endwith %}
<p>
<strong>Credit Card Expiry:</strong>
{%with field = "booking.CardExpMonth"|field %}
<select name="{{field.Name}}">
{%option field "1" "Jan"%}
{%option field "2" "Feb"%}
{%option field "3" "Mar"%}
{%option field "4" "Apr"%}
{%option field "5" "May"%}
{%option field "6" "Jun"%}
{%option field "7" "Jul"%}
{%option field "8" "Aug"%}
{%option field "9" "Sep"%}
{%option field "10" "Oct"%}
{%option field "11" "Nov"%}
{%option field "12" "Dec"%}
</select>
{% endwith %}
{%with field = "booking.CardExpYear"|field %}
<select name="{{field.Name}}">
{%option field "2008" "2008"%}
{%option field "2009" "2009"%}
{%option field "2010" "2010"%}
{%option field "2011" "2011"%}
{%option field "2012" "2012"%}
</select>
{% endwith %}
</p>
<p class="buttons">
<input type="submit" value="Proceed">
<a href="{%url "Hotels.Show" hotel.HotelId %}">Cancel</a>
</p>
</form>
<script type="text/javascript" charset="utf-8">
$(function() {
$(".datepicker").datepicker({dateFormat: 'yy-mm-dd'});
});
</script>
{% include "footer.html" %}