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.

Way to push variables to recycle templates?

June 01, 2012 7:49pm

Subscribe [4]
  • #1 / Jun 01, 2012 7:49pm

    ehime

    6 posts

    just curious if there’s a way to carry variables with you to the next template, I thought (coming from a PHP background) that posting variables would be a way, but this would have a form requirement.

    Here’s an example to illustrate my point

    I have several templates currently that basically do the same thing, but
    with small variable changes. Here’s an index

    {html_head}
    {embed="multiverse/.html_header" page_title="Product" body_class="p-product"}
    {embed="multiverse/.navigation"}
    
      {embed="products/.dynamic_feature-block"}
    
      {embed="products/.products_module" chan="products" cat_id="3" stat="featured|open" limt="12"}
    
    {embed="multiverse/.html_footer"}
    {html_close}

    and here’s a sample of one of the product pages (Laptops in this scenario)

    {html_head}
    {embed="multiverse/.html_header" page_title="Laptops" body_class="p-product"}
    {embed="multiverse/.navigation"}
    
      {embed="products/.dynamic_feature-block"}
    
      {embed="products/.products_module" chan="products" cat_id="6" stat="featured|open" limt="12"}
    
    {embed="multiverse/.html_footer"}
    {html_close}

    You can see that the only “Actual” differences between these two are
    A: Page title
    B: Category ID number

    Not a whole lot eh?

    So here is a chance that I can basically clip the 7 templates, and recycle
    them using one master instead. I guess the real question is, how would I carry over
    those variables from one page to the next, so on .products_module

    <section id="{embed:chan}" class="product-content">
       <div class="wrap">
        <hgroup>
         <h1>Routers</h1>
         <ul id="prod-subnav">
          <li><a href="http://{path=">Routers</a></li>
          <li><a href="http://{path=">Mobile</a></li>
          <li><a href="http://{path=">Laptop</a></li>
          <li><a href="http://{path=">Tv & DVR</a></li>
          <li><a href="http://{path=">USB</a></li>
         </ul>
        </hgroup>
    
        <ul class='list-column-3'>
        {exp:channel:entries channel="{embed:chan}" category="{embed:cat_id}" status="{embed:stat}" limit="{embed:limt}" paginate="bottom"}
         {if no_results}No Products in this Channel, check channel info?{/if}
         <li>
          <hgroup>
           {if product_blurb_image}{product_blurb_image}{/if}
    
           <h1>{title}</h1>
           {product_blurb}
    
           <!--/** Something like this maybe?
             *
             * <?php 
             * $assign_to_config['global_vars'] = array("{title}" => array( 
             *                                          "category" => "{cat_id}", 
             *                                          "title" => ucwords("{category_name}"));
             * ?>
             *
             */ -->
    
          </hgroup>
          <a href="http://{embed:chan}/{url_title}class=red-btn">Learn More</a>
         </li>
      
         {switch="||</ul><ul class='list-column-3'>"}
    
            {paginate}
                <li>Page {current_page} of {total_pages} pages {pagination_links}</li>
            {/paginate}
      
        {/exp:channel:entries}
        </ul>
    
        <div class="clear"></div>  
    
       </div><!--/wrap-->
      </section><!--/{embed:chan}-->
  • #2 / Jun 02, 2012 12:05am

    Enviromed

    375 posts

    Welcome to the wonderful world of low variables. . .which grows in functionality by leaps and bounds http://gotolow.com/addons/low-variables

    Make sure to understand ee parse order and partials.  avoid the extra overhead of embed templates.

    Good luck!

  • #3 / Jun 04, 2012 12:54pm

    Shane Eckert

    7174 posts

    Hi ehime,

    I second the input from Enviromed. Low Variables is the way to go.

    Is there anything else we can help you with?

    Cheers,

  • #4 / Jun 25, 2012 2:35pm

    OwanH

    87 posts

    Hi ehime,

    I agree with the others. Low Variables is a good way to go with this one. You can also check out the Stash module (http://devot-ee.com/add-ons/stash) as well. Both of these modules are excellent choices for tackling what you want to do.

    All the best!

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

ExpressionEngine News!

#eecms, #events, #releases