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.

EE tags in PHP, trying to use value from one channel in a different channel entries tag

November 01, 2011 2:36pm

Subscribe [2]
  • #1 / Nov 01, 2011 2:36pm

    Charley Parker

    60 posts

    I’m trying to pull a value from an entry in one EE channel, make it a PHP var and reuse the value to limit the returns in a different EE channel.

    {exp:channel:entries channel="publications_lancaster_current_pages"} 
    <?php 
    $theYear = "{subpage_year}";
    ?>
    {/exp:channel:entries}
     
     
      <ul>
     {exp:channel:entries channel="publications_lancaster_current_entries" dynamic="no" search:article_year="<?php echo $theYear; ?>"} 
      <li><a href="http://{title_permalink=publications/listing_lancaster_current}">{title}</a></li>  
     {/exp:channel:entries}
     </ul>

    PHP is turned on for the template and set to Input and is working fine.

    The problem is that the way I’ve declared the var is as a literal “{subpage_year}”, which works OK only within its original channel:entries tags. If I try to use the EE tag without the quotes to set the var, I get a PHP error.

    How can I get the value of {subpage_year} and use it in a different channel?

    Maybe there’s a way to do this without PHP?

  • #2 / Nov 01, 2011 2:47pm

    Brad K Morse

    178 posts

    Try having this on your main page

    {exp:channel:entries channel="publications_lancaster_current_pages"}
     {embed="template_group/template" subpage_yr = "{subpage_year}"}
    {/exp:channel:entries}

    Then create a new template, which will be embedded, as you see in the second line of the code above (below is the code for the embedded template)

    {exp:channel:entries channel="publications_lancaster_current_entries" dynamic="no" search:article_year="{embed:subpage_yr"}
    {if count==1}<ul>{/if}
      <li><a href="http://{title_permalink=publications/listing_lancaster_current}">{title}</a></li>
    {if count==total_results}</ul>{/if}
    {/exp:channel:entries}
  • #3 / Nov 01, 2011 3:50pm

    Charley Parker

    60 posts

    Works like a charm! Thanks!

    I never would have thought to use an embedded template to get around that limitation. Great to know.

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

ExpressionEngine News!

#eecms, #events, #releases