Influence Twig parse order?
Short answer: Cannot be done :)

Twig doesn't really have a "parse order", it compiles to plain old PHP. Upon compilation, this would make your Twig snippet basically this:

$myVariable = 'someInitialValue';
echo $entry-&gt;title . $myVariable;
$myVariable = 'example';
echo $entry-&gt;title . $myVariable;


Obviously, setting $myVariable to "example" the second time won't affect the output of the first echo statement.

An obvious way of accomplishing basically the same thing, would be to wrap the whole template in a {% set %} call – then your options would be many, you could for instance use placeholders and the replace filter:

{% set myContent %}
   {{ entry.title | myFilter }} {# myFilter appends placeholder "%myPlaceholder%" to the input #}
{% endset %}
{# Echo the template, replacing the placeholders with whatever #}
{{ myContent | replace( { "%myPlaceholder%", craft.myPlugin.getVar } ) }}


I get that this is not what you really want though.

If you really want to get your hands dirty you can see if you can find a way to manipulate the Twig internals.

You can access the Twig instance in your plugin via the TemplatesService:

$twig = craft()-&gt;templates-&gt;twig;


I guess that one way to achieve what you want is to write your own Lexer – fairly ambitious stuff for doing something easily done by extends, embeds or by output buffering/set and replace as per my example above.

Other concepts to look at (which may or may not be useful to your quest!) are Template hooks, global Twig variables, template embedding or Twig's StringLoader extension.

Finally, I'm quite curious about the actual use case here. If you'd care to elaborate, I'd love to know why you need/want to do this.