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.

assigning global variables in embedded templates

December 09, 2007 9:39am

Subscribe [3]
  • #1 / Dec 09, 2007 9:39am

    stef25

    268 posts

    im trying to use more embedded templates so i dont have to repeat almost identical code across a dozen templates. the only difference in the code is the value of “number” (my cat id)

    template: articles/travel-books:

    {assign_variable:number="220"}
    {embed="includes/article-organiser"}


    template: includes/article-organiser:

    {if segment_3 == ""}
       {embed="includes/category-select" cat_id="{number}"} 
    {/if}

    should this work? it seems the value i assign to my own variable (220) isnt getting carried over in to article-organiser. if i substitute cat_id=”{number}” with cat_id=“220”, it works fine.

    am i using global variables wrongly?

  • #2 / Dec 09, 2007 10:18am

    PXLated

    1800 posts

    You’re probably running into a parse order problem. You’ll more than likely need to use Embed Variables…EE-Docs
    And, you might be interested in this ongoing tutorial series at Jambor-EE where they use them quite extensively.

  • #3 / Dec 09, 2007 11:10am

    Boyink!

    5011 posts

    You haven’t coded a global variable in the example shown - you’ve coded a variable at the template level and you haven’t passed it to the second embedded template (article-organiser).

    Either you need to pass it to the embedded template or you need to define a true global variable in templates > Global Variables.

  • #4 / Dec 09, 2007 11:14am

    stef25

    268 posts

    thanks for the feedback. im now using embed variables, but the value is still not getting carried across

    travel-books:

    {embed="includes/article-organiser" test="220"}

    article-organiser:

    {if segment_3 == ""}
       {embed="includes/category-select" cat_id="{test}"} 
    {/if}

    —-

    @Boyink

    you need to pass it to the embedded template

    how would i do that?

  • #5 / Dec 09, 2007 1:52pm

    Boyink!

    5011 posts

    Well, the first place to look is the documentation around embedded variables with embedded templates, as they specify the formatting.

  • #6 / Dec 09, 2007 1:59pm

    PXLated

    1800 posts

    Yep…same link I gave…and a working example at Jambor-EE
    😉

  • #7 / Dec 09, 2007 3:11pm

    stef25

    268 posts

    d’oh! cat_id=”{test} shoulda been cat_id=”{embed:test}. this was the first d’oh but will not be the last. im in the process of moving a 4000 page site over from textpattern to ee. should be interesting

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

ExpressionEngine News!

#eecms, #events, #releases