Created
August 27, 2011 06:24
-
-
Save jesseyv/1175064 to your computer and use it in GitHub Desktop.
Tornado Template Syntax
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
Basic Output | |
Hello, {{ current_user.name }} | |
Basic Logic | |
{% if not current_user %} | |
You're not logged in! | |
{% elif current_user and curent_user.is_admin %} | |
Good day, sir! | |
{% else %} | |
Howdy! | |
{% end %} | |
{% for link in links %} | |
<a href="{{ link.href }}">{{ link.title }}</a> | |
{% end %} | |
{% set i = 10 %} | |
{% while i %} | |
Item {{ i }} | |
{% set i -= 1 %} | |
{% end %} | |
{% try %} | |
{{ undeclared_var }} | |
{% except NameError, e %} | |
{{ e }} | |
{% end %} | |
{{ globals().get('undeclared_var') }} | |
Inheritance | |
<!-- base.html Template --> | |
<body> | |
<div id="main"> | |
{% block main %} | |
You'll see me if the 'main' block isn't overridden | |
{% end %} | |
</div> | |
</body> | |
<!-- home.html Template --> | |
{% extends "base.html" %} | |
{% block main %} | |
Now you see me! | |
{% end %} | |
Comments | |
{% comment "I'm a comment" %} | |
Includes | |
{% include "other_template.html" %} | |
Imports | |
{% import os %} | |
{% import sys %} | |
Setting Variables | |
{% set DEBUG = True %} | |
{% set BASEPATH = os.getcwd() %} | |
Applying a function to a block | |
{% apply escape %} | |
<h1>Hello World</h1> | |
{% end %} | |
output: <h1>Hello World</h1> | |
{% apply base64.b64encode %} | |
Base64 Encode Me! | |
{% end %} | |
output: CkJhc2U2NCBFbmNvZGUgTWUhCg== |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment