We make tools that make websites.

Forums (Archived)

The Solspace Support Forums are now CLOSED (read-only)

Check out our new support options here. Please refer to this blog post for more information.

   

Template Morsels within logged_in/out conditionals

RankRank

Total Posts: 67

Joined: May 3, 2005

PM

Ignore

 

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?

Avatar
RankRankRankRankRank

Total Posts: 9901

Joined: Jan 8, 2009

PM

Ignore

 

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 smile

Signature

RankRank

Total Posts: 67

Joined: May 3, 2005

PM

Ignore

 

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.06MBTag{exp:template_morsels:fetch name="header_logged_in"}
(0.020446 1.06MBNo Closing Tag
(0.020564 1.06MBTag{exp:template_morsels:fetch name="header_logged_out"}
(0.020660 1.06MBNo Closing Tag 
Avatar
RankRankRankRankRank

Total Posts: 9901

Joined: Jan 8, 2009

PM

Ignore

 

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. smile 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. smile

Signature

RankRank

Total Posts: 67

Joined: May 3, 2005

PM

Ignore

 

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.

Avatar
RankRankRankRankRank

Total Posts: 9901

Joined: Jan 8, 2009

PM

Ignore

 

Sounds good smile
Glad I could help. If we’re good here, is it alright to close the thread?

Signature

RankRank

Total Posts: 67

Joined: May 3, 2005

PM

Ignore

 

Yes, please close the thread. You have answered my question.

Avatar
RankRankRankRankRank

Total Posts: 9901

Joined: Jan 8, 2009

PM

Ignore

 

Thanks. I’ll close the thread then, but feel free to post again if you have other questions smile

Signature