Skip to content

Osso/smartytotwig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smarty to Twig

CI

Converts Smarty 3 templates to Twig templates.

Based on https://github.com/freshrichard/smartytotwig

Installation

pip install git+https://github.com/osso/smartytotwig.git

Or for development:

git clone https://github.com/osso/smartytotwig.git
cd smartytotwig
uv sync

Usage

smartytotwig --smarty-file=examples/guestbook.tpl --twig-file=output.twig

Supported Features

  • 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

Requirements

  • Python 3.12+

About

Converts templates in the smarty templating language to the twig templating language.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages