# microtemplates **Repository Path**: yitx/microtemplates ## Basic Information - **Project Name**: microtemplates - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-07-24 - **Last Updated**: 2025-07-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README microtemplates.py ================= A toy templating engine. Accompanying blog post: [http://alexmic.net/building-a-template-engine/](http://alexmic.net/building-a-template-engine/). ## Why? I just wanted to learn how to write a templating engine. It's not feature-complete or production-ready. It's a playground and it will be a work in progress. ## Documentation There are two types of tags, `blocks` and `variables`. ### Variables ```html
{{my_var}}
``` ### Blocks There are three types of blocks – `if`, `each` and `call`. #### Loops ```html {% each items %}
{{it}}
{% end %} {% each [1,2,3] %}
{{it}}
{% end %} ``` `it` references the current item in the iteration and it is scoped to this item's attributes. To access attributes of the parent context use `..`. For example: ```html {% each items %}
{{..name}}
{{it}}
{% end %} ``` #### Conditionals Supported operators are: `>, >=, <, <=, ==, !=`. You can also use conditionals with things that evaluate to truth. ```html {% if num > 5 %}
more
{% else %}
less or equal
{% end %} {% if items %}
we have items
{% end %} ``` #### Callables Callables can get passed positional or keyword arguments. ```html
{% call prettify date_created %}
{% call log 'here' verbosity='debug' %}
``` ## Benchmarks Using `benchmarks.py` and the templates files in `templates/` here are the results: ``` microtemplates => run 10000 times, took 0.36 ms django => run 10000 times, took 0.95 ms django_default_loader => run 10000 times, took 1.16 ms django_cached_loader => run 10000 times, took 0.46 ms jinja2 => run 10000 times, took 5.64 ms jinja2_env => run 10000 times, took 0.08 ms ```