Skip to content

Instantly share code, notes, and snippets.

@brh55
Last active September 18, 2015 13:54
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 brh55/953e5a3e863822a4e324 to your computer and use it in GitHub Desktop.
Save brh55/953e5a3e863822a4e324 to your computer and use it in GitHub Desktop.
Optimized Conditionals for MODx | PMACS Web Team | #MODx #optimizing
1. [[[[*show-sidebar:is=`yes`:then=`$sidebar`:else=`$subpage-content`]]]]
Now we tell modx to check if it is true, then parse either sidebar or subpage-content!
2.[[[[*back-to-top:is=`yes`:then=`$back-to-top`]]]]
3. [[*show-caption:is=`yes`:then=`$caption`]]
Chunk named Caption:
<p class="flex-caption">[[+caption]]</p>
While we tend to use a lot of conditionals in our workflow, we forget that MODx has to parse each individual tag resulting in performance degradation.
For more information on why this is the case, please check out this link:
http://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/
Thus we need to focus on eliminating unncessary tags to create better order for MODx. This prevents parsing too many unncessary things in order to get the results we are aiming for. While, some things that are just small to parse like a line of code may not be worth the time of revising, but if they are longer, it is good to revise it.
Below are common and simple examples of our current conditionals, and then newer methods of optimizing it.
1. [[*show-sidebar:is=`yes`:then=`[[$sidebar]]`:else=`[[$subpage-content]]`]]
Whats wrong: We are telling MODx to parse the sidebar and parse the subpage content, now check if show-sidebar is true. If it is just display the sidebar content, otherwise display subpage content.
2. [[*back-to-top:is=`yes`:then=`[[$back-to-top]]`]]
3. [[*show-caption:is=`yes`:then=`<p class="flex-caption">[[+caption]]</p>`]]
[For this use case it isn't beneficial, but if it was lots of lines of code, then it could be enhanced following similar method]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment