Is there a way to create {% %} directive?

I'm trying to align my templating system to use both Swig and Volt and there are few differences between them. It doesn't appear to be possible in Swig to use {{ func(1, 2, 3) }} format and instead it wants to see {% func 1 2 3%}.

I stimulated a node developer to create a Swig gettext string extractor and it appears to work. I'd rather not be jumping back and forth between Swig and Volt since they use two different function formats.

So is it possible to extend the {% %} tags so that I could use {% _ 'Singular Form' 'Plural Form' %} for translation strings? Notice that there are no parenthesis in the {% %} format.

Any Volt wizards around here?

You mean write literal {% %} ? Maybe this code can lead you to right direction:

$this->getCompiler()->addFunction('swig', function($input) {
  return '"{% ".' . $input . '." %}"';
});

Using in template

{{ swig("_ 'Singular Form' 'Plural Form'") }}

Will compile to:

{% _ 'Singular Form' 'Plural Form' %}


44.7k
edited Nov '14

I don't need to make Swig templates from Volt. I'm trying to use Volt in a way that is more similar to Swig. It doesn't appear easy to override the {% %} syntax and so Volt doesn't easily support extending the language and only adding functions.