Skip to content

Instantly share code, notes, and snippets.

@tomill
Created November 11, 2014 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomill/339487f9c0859a8b135d to your computer and use it in GitHub Desktop.
Save tomill/339487f9c0859a8b135d to your computer and use it in GitHub Desktop.
tt-to-twig.pl
use strict;
use warnings;
local $| = 1;
while (my $line = <>) {
$line =~ s/\[% WRAPPER '(.+?)' %\]/{% extends "layout.html.twig" %}\n{% set pageid = '' %}\n\n{% block content %}/g;
$line =~ s/\[% END # WRAPPER %\]/{% endblock %}/g;
$line =~ s/\[% FOREACH (.+?) IN (.+?) %\]/{% for $1 in $2 %}/g;
$line =~ s/\[% END # FOREACH %\]/{% endfor %}/g;
$line =~ s/\[% IF (.+?) %\]/{% if $1 %}/g;
$line =~ s/\[% ELSE %\]/{% else %}/g;
$line =~ s/\[% END # IF %\]/{% endif %}/g;
$line =~ s/\[% END %\]/{% endfixme %}/g;
$line =~ s!\[% (.+?) %\]!
my $var = $1;
$var =~ s{\|\|}{?:};
$var =~ s{//}{?:};
$var =~ s{ _ }{ ~ }g;
sprintf '{{ %s }}', $var;
!ge;
print $line;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment