Published by Mijingo

tips icon image

EE Insider Tips
Sponsored by Mijingo's EE 2 Screencasts

ExpressionEngine mini-howtos created by the EE Insider community.

Embed an Embed within Itself?

User's avatar
  • Posted by Trevor Davis
  • October 17, 2009
  • 1 person has found this tip helpful.

I just wrote a blog article about this, but I figure it would be good to share here too.

We wanted to be able to show an entry that was tagged with a certain category, and if no entries were found, just show an entry with any or no category. I couldn’t think of a good way to do this, and I knew I couldn’t nest exp:weblog:entries tags.

The code we were working with was already in an embed file, so we just embedded the same embed within the embed without the category parameter. Even though the documentation (notes section) says you can’t do this, we knew that we would never be creating an infinite loop, so it worked.

Here is the code from our embed:

{assign_variable:channel_name="{embed:channel}"}
{assign_variable
:category_id="{embed:category}"}
{assign_variable
:show_expired="{embed:show_expired}"}

{exp
:weblog:entries weblog="{channel_name}" category="{category_id}" show_future_entries="yes" show_expired="{show_expired}" limit="1" disable=“category_fields|custom_fields|member_data|pagination|trackbacks”}

    
<h2>{title}</h2>
            <
class="rightSide"><a href="{url_title_path="{embed:template_path}"}"><img src="{events_feature_image}" alt="" /></a>
                
{events_summary}
    
    
<a href="{url_title_path="{embed:template_path}"}" class="more">Read more »</a>

    
{if no_results}
        {embed
=“site/.events” channel=“events” show_expired=“yes” template_path=“news-events/events”}  
    {
/if}            
    {
/exp:weblog:entries} 

And then you would include that embed file by doing this:

{embed=“site/.events” channel=“events” category=“7” show_expired=“no” template_path=“news-events/events”} 

Add Your Comment?

You must have an EE Insider account to post comments on Insider Tips. It's fast, easy and hassle-free.

Sign up now (or login).

Search EE Insider Tips
Sponsored By