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.

ExpressionEngine stored values or variables?

July 06, 2011 9:19pm

Subscribe [4]
  • #1 / Jul 06, 2011 9:19pm

    csmkt

    5 posts

    All I want to do is to take the values in an EE tag and reuse it in another EE tag.

    E.g. Below is a breadcrumb, and I want to grab the parent category ID (here I’ve stored it in a PHP variable “$parent_cat_id”)...

    {exp:gwcode_categories entry_id="{entry_id}" style="linear" limit="3"}
        <a href="http://{path=">{cat_name}</a> <?php $parent_cat_id = {cat_id}; ?> »
    {/exp:gwcode_categories}

    ... so that it can be used in another EE tag (in the code, you can see the php tag inside the parameter “cat_id”)...

    {exp:gwcode_categories cat_id="<?=$parent_cat_id?>" style="linear" class="tabs" last_only="yes"}
      <li{if segment_2 == url_title} class="active"{/if} {if count == 1}id="first-tab"{/if}>
        <a href="http://{cat_url_title}">{cat_name}</a>
      </li>
    {/exp:gwcode_categories}

    In the above code, the PHP variable “parent_cat_id” can be echoed outside of the EE tags, but not inside… I have not found an equivalent to the PHP variable. I have tried nesting the first EE tag inside the second, tried using the {preload_variable}, tried putting an EE query inside the gwcode_categories tag.

    Any other thoughts or suggestions? I greatly appreciate it. Thanks!

    Note: I am running Expression Engine 2.2.0.

  • #2 / Jul 06, 2011 10:44pm

    gwineman

    19 posts

    If you embed the second set of code and pass the php variable through the embed, it should work.  Make sure you have php parsing stage set to output on the template where you are using php

    {exp:gwcode_categories entry_id="{entry_id}" style="linear" limit="3"}
        <a href="http://{path=">{cat_name}</a> <?php $parent_cat_id = {cat_id}; ?> »
    {/exp:gwcode_categories}
    
    
    {embed="template" catid="<?= $parent_cat_id?>"}


    Embedded Template

    {exp:gwcode_categories cat_id="{embed:catid}" style="linear" class="tabs" last_only="yes"}
      <li{if segment_2 == url_title} class="active"{/if} {if count == 1}id="first-tab"{/if}>
        <a href="http://{cat_url_title}">{cat_name}</a>
      </li>
    {/exp:gwcode_categories}
  • #3 / Jul 07, 2011 8:18am

    John Henry Donovan

    12339 posts

    csmkt,

    gwineman’s advice is good. Can you try that and let us know if that worked for you.

    Note that you can change the PHP parse order of a template in it’s prefs from Output to Input too

  • #4 / Jul 07, 2011 12:47pm

    csmkt

    5 posts

    I just want to thank you both for your replies, embedding another template worked great! This would have been a huge time-saver. Appreciate it.

  • #5 / Jul 07, 2011 4:08pm

    Sue Crocker

    26054 posts

    Glad things are working again.. If anything else comes up, please do let us know in a new thread..

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

ExpressionEngine News!

#eecms, #events, #releases