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 tags in embeds

September 26, 2011 8:43pm

Subscribe [6]
  • #1 / Sep 26, 2011 8:43pm

    nicktpw

    29 posts

    This question may be related to a resolved thread.

    I want to show information from 2 different channels on one page, and I read this thread and am trying to get the second channel’s information through using an embedded template.

    However, I’m not getting anything from the channel tag to show from the embedded template. The divs I set up are working and showing, but nothing inside the channel tag is displaying.

    any ideas? much appreciated!

  • #2 / Sep 27, 2011 1:31am

    John Henry Donovan

    12339 posts

    nicktpw,

    If you wish to just show info from 2 different channels on one page then just use 2 Channel Entry Tags

    {exp:channel:entries channel="news" dynamic="no"}
        {title}
    {/exp:channel:entries}  
    
    {exp:channel:entries channel="services" dynamic="no"}
        {title}
    {/exp:channel:entries}

    You would use an embed if you wish to pass info from one Channel to another Channel to affect results for second Channel

    Does that help?

  • #3 / Sep 27, 2011 12:49pm

    nicktpw

    29 posts

    is the dynamic tag what allows both to run on the same page like that? I need to give that a try…

    Also, how would i pass info from one channel to another through an embed? That would be ideal. Can I use variables from custom fields in the first channel in the embedded template?

  • #4 / Sep 27, 2011 6:00pm

    Boyink!

    5011 posts

    is the dynamic tag what allows both to run on the same page like that? I need to give that a try…

    Technically in this case John’s got the tags to be non-dynamic, which in EE-land means “not reading the URL to do anything”.  In other words, with the dynamic property set to no the tags will always return the same content regardless of what URL the template is loaded at.

    Also, how would i pass info from one channel to another through an embed? That would be ideal. Can I use variables from custom fields in the first channel in the embedded template?

    Start by reviewing how Embedded templates work.

    Then play around with tag pairs used in place of the fixed variable values…;)

  • #5 / Sep 29, 2011 8:52am

    Sue Crocker

    26054 posts

    Thanks for the assist, Mike.

    nicktpw - does that info help?

  • #6 / Oct 01, 2011 4:21pm

    nicktpw

    29 posts

    halfway there. the dynamic tag fixed the problem for getting the second channel entries to load.

    still a bit confused about how to get a variable from a custom field in the first channel to the channel in the embedded template.

  • #7 / Oct 01, 2011 6:56pm

    Boyink!

    5011 posts

    still a bit confused about how to get a variable from a custom field in the first channel to the channel in the embedded template.

    Can you describe the higher goal of what you are trying to do (vs. the way you are trying to do it)?

     

  • #8 / Oct 01, 2011 7:42pm

    nicktpw

    29 posts

    sure.

    i have a channel called ‘x’ that has two custom fields, one for a body of copy {body}, and another field that will hold the number of a specific category {xcategory}. That number is related to channel that I am using in the embedded template.

    when i display the info from channel ‘y’, I only want to display info from a specific category from that channel that I defined in {xcategory}.

    does that make sense? if not I can paste in code.

  • #9 / Oct 03, 2011 6:58am

    Boyink!

    5011 posts

    Hmmm…

    How about a higher level explanation yet.

    Are you trying to display related articles in a sidebar?

  • #10 / Oct 03, 2011 11:52am

    nicktpw

    29 posts

    not trying to display articles in a sidebar.

    Here is one of the pages in question:

    http://thepublicworks.biz/_ee/brand_stimulation/design_engineering

    There are 5 pages that use this template, and they are in the ‘brand_stimulation” channel. The top level menu item will show all of the entries from the ‘projects’ channel as you’ll see in the link. However, I want the 4 menu items (‘design/engineering,’ ‘photography,’ ‘brand development,’ and ‘fabrication’) to show only a certain category from the ‘projects’ channel.

    I have created a custom field in the ‘brand_stimulation’ channel where I can enter the number of the ‘projects’ category I want to show specifically on that page. My problem is that I don’t know how to pass the value of that field to the embedded template which displays the information from the ‘projects’ channel.

    Main template code:

    {embed="home/header"} <!-- embed header template -->
    
    <!-- begin template -->
    
    <link href="http://www.thepublicworks.biz/css/brandstim.css" rel="stylesheet" type="text/css">
    
    {exp:channel:entries channel="brandstim"}
        
        <title>{tpw} | Brand Stimulation | {title}</title>
    
     <div id="brandstimboxouter" class="background"> <!-- begin div brandstimbox -->
        
     <div id="brandstimbox"> <!-- begin div slidebox -->
            
     {title}
     
     <div class="brandstimtext"> <!-- begin div brandstimtext -->
     {brandstimtext}
            
     </div> <!-- end div brandstimtext -->
        
        </div> <!-- end div slidebox -->
        </div> <!-- end div brandstimbox -->
     
    {/exp:channel:entries}   
         
    {embed="brand_stimulation/projectsbox"} <!-- embed sidebar template -->

    Embedded template code:

    <div id="projectsholder">  
          
    {exp:channel:entries channel="projects" paginate="bottom" limit="8"  dynamic="no" orderby="title" sort="asc"}
    
     <div id="projectbox"> <!-- begin div projectbox -->
    
      <div id="projectinner" class="background"> <!-- begin div projectinner -->
      
            <a href="http://{url_title_path=%27projects/index%27}" class="black">_     {exp:char_limit total="20"}_        _  {title}_        _        {/exp:char_limit}_        _        </a>
            
          <div id="projectimage"> <!-- begin div projectimage -->
          {projects_image_1}
                </div> <!-- end div projectimage -->
    
      </div> <!-- end div projectinner -->
            </div> <!-- end div projectbox -->
            
         {paginate}
      <div id="paginate">Page {current_page} of {total_pages} {pagination_links}</div>
      {/paginate} 
    
       {/exp:channel:entries}     
        
        </div>
    
    {embed="home/footer"}  <!-- embed footer template -->
  • #11 / Oct 03, 2011 1:59pm

    Dan Decker

    7338 posts

    nicktpw,

    In order to pass the value of that field to your embedded template, your embed call need to be inside you {exp:channel:entries} pair. In order to do that, you need to protect the embed from being ran for each entry. So try this:

    {embed="home/header"} <!-- embed header template -->
    
    your template code
     
    {if {count} == {total_results}}
    {embed="brand_stimulation/projectsbox” pass_category="{xcategory}"} <!-- embed sidebar template -->
    {/if}
    {/exp:channel:entries}  
    
    {embed="home/footer"}  <!-- embed footer template -->

    Note that you would then move your embed for footer below the closing {/exp:channel:entries}

    and in your embed template:

    <div id="projectsholder">  
          
    {exp:channel:entries channel="projects" paginate="bottom" limit="8"  dynamic="no" orderby="title" sort="asc" category="{pass_category}"}
    
    your template code
    
    {/exp:channel:entries}     
        
        </div>

    Let us know if you have any questions
       

  • #12 / Oct 03, 2011 6:38pm

    nicktpw

    29 posts

    Not working… Info from the embedded template isn’t showing up.

    Tried with and without the loop, results did not vary.

    Is there in easier way to do this? Or is the way I’m thinking the only logical way to do it?

  • #13 / Oct 03, 2011 8:09pm

    Boyink!

    5011 posts

    This is probably the most straightforward way to do this.

    It’s actually not that hard - it’s just a matter of determining if you have the two templates connected and then making sure the right value is getting passed.

    The best thing to do in “not working” cases is simplify. 

    In the embedded template - strip everything out except for just the word “yes”.

    Then in the parent loop try just:

    {if {count} == {total_results}}
    {embed="brand_stimulation/projectsbox”}
    {/if}</code></pre>
    
    Run that.
    
    The result here is that you should get the word "yes" once in your loop results.
    
    Not getting it?  Then strip it back to just:
    
    <pre><code>{embed="brand_stimulation/projectsbox”}</code></pre>
    
    Still not working?  Must be a naming thing - make sure there is a template group called brand_stimulation and a template called "projects box".
    
    Working?  Good.
    
    Now try putting the conditional back in place.  Not working?  Try:
    
    <pre><code>{if count == total_results}
    {embed="brand_stimulation/projectsbox”}
    {/if}</code></pre>
    
    Working?  Now add the embed variable back in.  In the parent template (working with Dan's code):
    
    <pre><code>{if {count} == {total_results}}
    {embed="brand_stimulation/projectsbox” pass_category="{xcategory}"}
    {/if}

    and in the embedded template:

    {embed:pass_category}

    The result here should be just displaying the category id.  Not working?  Again, must be a naming thing.  The name of the variable must match between parent and embedded templates.

    Working?  Cool.  Then try the rest of Dan’s code:

    <div id="projectsholder">  
          
    {exp:channel:entries channel="projects" paginate="bottom" limit="8"  dynamic="no" orderby="title" sort="asc" category="{pass_category}"}
    
    your template code
    
    {/exp:channel:entries}     
        
        </div>

    Not working?  Try replacing the embed variable with a hardcoded value - just to make sure it works that way.

    Again, when something doesn’t work simplify back until it does work then add complexity slowly and incrementally.

  • #14 / Oct 05, 2011 2:22pm

    Dan Decker

    7338 posts

    nicktpw,

    Did Michael’s run down help you troubleshoot your embeds? Let us know your progress.

    Cheers,

  • #15 / Oct 05, 2011 5:03pm

    nicktpw

    29 posts

    The code works with the loop with the pass_category, but once I implement the code into the entries code in the embedded template, it stops working.

    I also don’t understand where to put this:

    ‘and in the embedded template:’

    {embed:pass_category}

    I feel like I have everything right, a bit stumped right now.

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

ExpressionEngine News!

#eecms, #events, #releases