I currently bring in a part of my header using the following:
{if logged_in}
{exp:template_morsels:fetch name="header_logged_in"}
{/if}
{if logged_out}
{exp:template_morsels:fetch name="header_logged_out"}
{/if}
It seems that Template Morsels is processing both morsels. Is this because it processes all morsels it finds in the template? Is there any way to change this behavior?
Hi Jim,
From my understanding, I believe both morsels are processed first because {exp:...} tags are parsed before conditionals such as {if logged_in}. Have a look at the parse order documentation for more details.
To get around this you could use third-party add-ons, such as Switchee, to get around this parse order issue, or maybe even use PHP (on input) to check if the user is logged in
Simple conditionals get parsed before ee tags. That why is you use a “if logged_in” conditional followed by a “if logged_out” conditional only the true one gets parsed. That’s not what seems to happening with TM.
Using this code:
{if logged_in}
{exp:template_morsels:fetch name="header_logged_in"}
{/if}
{if logged_out}
{exp:template_morsels:fetch name="header_logged_out"}
{/if}
Template debugging shows this:
(0.020353 / 1.06MB) Tag: {exp:template_morsels:fetch name="header_logged_in"}
(0.020446 / 1.06MB) No Closing Tag
(0.020564 / 1.06MB) Tag: {exp:template_morsels:fetch name="header_logged_out"}
(0.020660 / 1.06MB) No Closing Tag
I had a discussion about {if logged_in} on Twitter, tested some code on my side, and checked out Low’s excellent slides from EECI on parse order just to be sure.
The slides can be seen here:
http://www.slideshare.net/lodewijkschutte/parse-order-pro
Have a look at slide 80 and proceed to slide 86. {if logged_in} is an advanced conditional, except for when it’s placed in a {exp:channel:entries} loop, where it is parsed along with the {exp:channel:entries} tag.
That seems to explain why both morsels are parsed.
Thanks for pointing that out. I have seen it before but I missed that part.
I’ve been spending time trying to get my head around the parse order to take advantage of the parsing order in my current redesign. Just when I think I’ve got it figured out, I find a new twist.
Thanks for helping me make progress.
I’ve refactored that part of my template to avoid advanced conditional.
Sounds good ![]()
Glad I could help. If we’re good here, is it alright to close the thread?
Yes, please close the thread. You have answered my question.
Thanks. I’ll close the thread then, but feel free to post again if you have other questions