Parse Order and Low Variables
It’s been a while since my last blog post about parse order in ExpressionEngine, so I think it’s time for new one. I’d like to explain how you can use Low Variables to use the parse order to your advantage. Get your parse order cheat sheet ready and let’s go!
What is “parsing”?
In ExpressionEngine, parsing a template simply means replacing all markers in the template with the actual content. In this case, the markers consist of variables and tags. One by one, new content is put into the template for each marker, thus creating a new template after each replacement. The order in which the markers are replaced is called the parse order. I’ve explained this in my Parse Order Pro talk.
Early vs. Late
Low Variables lets you create global variables. By default, these are parsed (replaced) at the very end of the parse order (stage 9, if you’re checking my cheat sheet). However, you can choose to enable Early Parsing for each variable, effectively making it a Snippet. These are parsed at the very beginning of the parse order (stage 1).
For early parsed vars, Low Variables offers even more granular control. Each one is parsed in the order in which it appears in its group, allowing you to nest them. Just be careful you don’t end up in parse order limbo.
Variables vs. Tags
So, Low Variables are either parsed at stage 1 or 9, depending on whether early parsing is enabled. But wait, there’s more. You can also choose to use tags to parse the variables, and tags are always parsed at stage 5, no matter what the early parsing preference is.
Using tags will allow you to avoid nesting conflicts, as Jamie Pittock explains here. Some variable types require you to use the tag syntax, so extra processing can be done before replacing the marker with its content, like Matrix. Remember, tags can have parameters, global variables cannot.
[cue Inception music] So, there are three stages at which a Low Variable can be parsed:
- As early parsed global variables using the variable syntax (stage 1);
- As tags, single or pair, using the tag syntax (stage 5);
- As late parsed global variables (the default) using the variable syntax (stage 9).
Looking at these stages, you can always nest variables upwards: 2 in 1, 3 in 1, and 3 in 2. As noted before, you can also nest 1 in 1, but only if they are in the same group and in the right order. Theoretically, you can nest 2 in 2, but that might cause your brain to melt. Nesting 3 in 3 won’t necessarily break things, but it can lead to unexpected results. Nesting 1 in 2, 1 in 3, or 2 in 3 will never work.
Parse Order never gets old
There you go. Low Variables will give you unprecedented control over what is parsed when, so you can create efficient and elegant templates that scale.