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.

   

Morsel embedded in an embed inside a exp:query loop only executes once?

Rank

Total Posts: 2

Joined: Jun 30, 2010

PM

Ignore

 

Using Template Morsels 1.5.4 and EE 2.2.2.

I’m having an issue where I have a template morsel being called from an embed which is embedded in an exp:query loop.

The first category loop gets output properly. All entries are shown for that category. But after that, nothing more is output.

Here’s a description of the system and sample code that shows the environment where the issue appears:

First, here’s the high level overview:

We have a monthly publication. Each month is it’s own category in a category group of issue months. On our table of contents page, we have each month’s issue output in it’s own “tab” content. Ie, click the August issue tab, and then you can see the August table of contents without incurring an additional page load as all content is loaded on the page.

The first loop gets each month:

index template:

{exp:query sql="SELECT * FROM exp_categories where group_id = '5' order by cat_order desc limit 8 offset 1" cache="yes" refresh="60"}

{embed
="updates/.updates_embed" month_cat_id="{cat_id}" toc="true"}

{
/exp:query} 


Inside of the monthly issue loop, we retrieve a table of contents for that specific month, for each of three separate primary content categories that we use. I’ve eliminated the code for categories unrelated to this problem, and will just feature our ‘Updates’ category output.

Each article in our Updates category is also assigned to a category subject. When output, the articles are sorted into their subcategories and output under a category header. I have to use a little PHP here to properly retrieve the requested Month category from the outer loop.

updates/.updates_embed template:

<?php
$month_cat_id 
'';
if (
strpos("{embed:month_cat_id}"'C') === 0)
{
    $month_cat_id 
str_replace('C''''{embed:month_cat_id}');
}
elseif ("{embed:month_cat_id}" == "")
{
    header
('Location: /se-news/');
    exit;
}
else
{
    $month_cat_id 
'{embed:month_cat_id}';
}
?>

<h2>Cat<?=$month_cat_id?></h2>
{exp:channel:categories channel="updates" category_group="12" style="linear"}

{exp
:template_morsels:fetch name="updates_embed_entries" month_cat_id="<?= $month_cat_id ?>" cat_id="{category_id}" cat_name="{category_name}" segment_2="{segment_2}"}

{
!-- below is the original template that has now moved to a morsel --}
{
!--embed="updates/.updates_embed_entries" month_cat_id='<?= $month_cat_id ?>' cat_id="{category_id}" cat_name="{category_name}"--}

{
/exp:channel:categories}


{if 
'{embed:toc}' != 'true'}
{embed
="se-news/.updates_embed_full" month_cat_id="<?= $month_cat_id ?>"}
{
/if} 

This is where the fun begins. On the first Month Loop through this template, the morsel is retrieved and the entire Month’s content for all subcategories is output. But after the first month, no more data from inside the morsel is output, not even the content outside of the channel:entries tag.

updates_embed_entries morsel content:

<h1>START</h1>
{exp:channel:entries channel="updates" category="{cat_id}&{month_cat_id}" status="open|closed" disable="categories|custom_fields|member_data|pagination"}
{if {count} 
== 1} {!-- show category header only if there are entries --}
<div class="clearfix">
    
{if "{cat_name}' == 'Google"}
    
<class='u_google'></p>
    
{if:elseif "{cat_name}' == 'Google UK"}
    
<class='u_google_uk'><span class="smallverdana">contributed by ...</span>
    </
p>
    
{if:elseif "{cat_name}' == 'Google AdWords"}
    
<class='u_adwords'><span class='smallverdana'>contributed by ...</span>
    </
p>
    
{if:elseif "{cat_name}' == 'Yahoo Search Marketing"}
    
<class='u_yahoo'></p>
    
{if:elseif "{cat_name}' == 'Bing"}
    
<class='u_msn'></p>
    
{/if}
</div>

<
ul class="updates clearfix">
    
{/if}

    {if 
"{segment_2}' == 'print_and_run"}
    
<li><span class="smallverdana"><a href="#{entry_id}">{title}</a></span>
    </
li>
    
{if:else}
    
<li><span class="smallverdana"><a href="/se-news/update/vol/{month_cat_id}/#{entry_id}">{title}</a></span>
    </
li>
    
{/if}
    {
/exp:channel:entries}
</ul>

<
h1>End</h1


This code works fine when used as a regular embed. The reason for the multiple levels of embeds was originally to try to cache the templates more cleanly.


Here’s an example of the output I would get:

Cat: 5
START
[ Google Header ]
- Article 1
- Article 2
END
START
[ Adwords Header ]
- Article 3
- Article 4
END
START
[ Yahoo Header ]
- Article 5
- Article 6
END
Cat: 4
Cat: 3
Cat: 2
Cat: 1

As you can see starting from Cat: 4, no more content from the morsel gets output.

I hope I’ve explained this enough. Please let me know if you have any ideas or questions.

Thanks,

Ian

Avatar
RankRankRankRankRank

Total Posts: 9901

Joined: Jan 8, 2009

PM

Ignore

 

Hi Ian,

This might not be related to the issue directly, but why are you using PHP in your embed code? From your query, I don’t think the {cat_id} will ever contain a “C” in it. Maybe that’s a place where some PHP overhead could be saved, and maybe avoid PHP input/output dilemas smile

What version of Template Morsels are you using?
What version of EE are you using? Thanks smile

Signature

Rank

Total Posts: 2

Joined: Jun 30, 2010

PM

Ignore

 

Thanks for the reply. I was able to solve my issue by rearranging the order of the embeds.


EDIT-

This thread was marked resolved, so I’m unable to reply.

To answer your question below, I’m using both embeds and Template Morsels. As you can maybe tell from the code I posted above, I have a very nested bunch of entries to output.

Here’s the morsel code:

{exp:channel:categories channel="updates" category_group="12" style="linear" show_empty="no" restrict_channel="yes"}
{embed
="news/.updates_embed_entries" cat_id="{cat_id}" category_id="{category_id}" category_name="{category_name}"}
{
/exp:channel:categories} 

This calls the embedded template (just about identical to the “updates_embed_entries morsel content” that I posted above) that contains the channel:entries tag. I had to move the entries tag into it’s own embed because I had to use the {count} value to avoid outputting empty category headers, and when left directly inside the categories tag, the {count} referred to the outer categories loop. Moving the entries tag to it’s own embed allowed the {count} value to refer to the inner entries loop.

All this necessary because show_empty=“no” does not work as you would expect.

Using the Template Morsel in this way reduced page load from 3+ seconds to ~500ms, so thanks for that. smile

Avatar
RankRankRankRankRank

Total Posts: 9901

Joined: Jan 8, 2009

PM

Ignore

 

Glad to hear you managed to fix your problem!
I also apologize for asking for Template Morsels and EE versions when I see you have that mentioned in your first post shut eye

So are you now using embeds or Template Morsels? Your problem appeared to hint at a order/parsing issue, but if you have some time I’d like to see how you solved your problem here grin
Thanks!

Signature