Converts Smarty 3 templates to Twig templates.
Based on https://github.com/freshrichard/smartytotwig
pip install git+https://github.com/osso/smartytotwig.gitOr for development:
git clone https://github.com/osso/smartytotwig.git
cd smartytotwig
uv syncsmartytotwig --smarty-file=examples/guestbook.tpl --twig-file=output.twig- Variables:
{$foo}→{{ foo }} - Object/array access:
{$foo->bar},{$foo.bar},{$foo['key']} - Modifiers/filters:
{$foo|bar:param}→{{ foo|bar(param) }} - nofilter:
{$foo nofilter}→{{ foo|raw }} - If/elseif/else statements
- Foreach loops with loop variables (
@iteration,@index,@total,@key) - Foreachelse
- Template inheritance:
{extends},{block} - Capture:
{capture name="x"}...{/capture}→{% set x %}...{% endset %} - Comments:
{* comment *}→{# comment #} - Literal blocks:
{literal}...{/literal} - Include:
{include file="foo.tpl"}→{% include "foo.twig" %} - Assign:
{assign var=x value=y}→{% set x = y %} - Delimiter tags:
{ldelim},{rdelim} - Comparison operators:
==,!=,<,>,<=,>=,eq,ne,neq,gt,lt - Logical operators:
and,or,&&,||,! - instanceof:
{if $foo instanceof Bar}→{% if foo is Bar %} - Function calls with parameters
- Python 3.12+