ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Channel call inside channel call...

December 06, 2011 10:35am

Subscribe [3]
  • #1 / Dec 06, 2011 10:35am

    Hundred

    8 posts

    NEWBIE: I’m trying to do a channel call (exp:channel:entries) inside another channel call with out success.

    This is because i’ve made a relation to choose a background image and some text about it.

    But if the user havn’t chosen a background picture a random background image should replace it.

    But i can’t make it work - are there an other way to the goal?

    {exp:channel:entries channel="text"}
    
    {title}
    
    {if background == 0}
     {exp:channel:entries channel="background_photo" orderby="random" limit="1"}
      background-image: url({photo});
     {/exp:channel:entries}
    {if:else}
     {related_entries id="Background"}
      background-image: url({photo});
     {/related_entries}
    {/if}
    
    {article_text}

     

  • #2 / Dec 06, 2011 10:43am

    Fuel

    44 posts

    Move your nested channel:entries loop into an embed and it will work. You cannot nest channel:entries tags within each other unless you embed the nested one.

  • #3 / Dec 06, 2011 3:31pm

    Hundred

    8 posts

    Still not working - but it helped a little, but what I didn’t mention is that the background image and the following text are placed to different places in the HTML – the image in a style in the header and the following text in a div inside the body…

    And then I need two embedded templates - but the random aint the same then 😕

    ...while writing this question im thinking about using embed variables…

    {exp:channel:entries channel="text_article"}
    <html>
    <head>
    <style>
    body {
     padding: 0;
     margin: 0;
    {if background == 0}
     {embed="includes/random_background" piece_name="Topper"}
    {if:else}
     {related_entries id="Background"}
      background-image: url({photo});
     {/related_entries}
    {/if} 
     background-position: top center; 
     background-repeat: no-repeat; 
     background-color: #333;
     background-attachment: fixed;
    }
    </style>
    </head>
    
    <body>
    
    {title}
    
    {if background == 0}
     {embed="includes/random_background" piece_name="Hest"}
    {if:else}
     {related_entries id="Background"}
    
     <div id="infoleft">
            {ingredients}
            </div>
      
            <div id="inforight">
             
             <h3>{title}</h3>
    <p>  {recipe_text}<br />
                <br />
            </div><br />
     <br />
     {/related_entries}<br />
    {/if}</p>
    
    <p></body><br />
    </html><br />
    {/exp:channel:entries}

    and the embedded random_background template:

    {exp:channel:entries channel="background_photo" orderby="random" limit="1"}
    
    {if embed:piece_name == "Topper"}
    
    background-image: url({photo});
    
    {if:else}
    
    <div id="infoleft">
     {ingredients}
    </div>
      
    <div id="inforight">
             
     <h3>{title}</h3>
    <p> {recipe_text}<br />
                <br />
    </div></p>
    
    <p>{/if}</p>
    
    <p>{/exp:channel:entries}

    But this doesn’t work - any ideas?

  • #4 / Dec 07, 2011 2:36pm

    Dan Decker

    7338 posts

    Hi Hundred,

    I have a couple of questions and a theory about why this may not be working. When you use the “id” parameter in your {related_entries} tag, that should be the “short_name” of the channel field you have assigned for relationships. Short names are typically lowercase and separated by underscores. In this case, I suspect the field’s short name is “background”? If you use the short name, does it properly pull your relationships?

    My theory is that the brackets “{}” used in CSS are interfering with your ExpressionEngine tags. If you break this down to a simple test, excluding the CSS and just trying to embed a second simple template, are your conditionals processed?

    Thanks!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases