1

Is there an alternate way to pass embed variables other than passing them as attributes?

1
  • You know you can put a complete module tag inside a parameter of an embed, right?
    – Sobral
    Nov 14 '13 at 10:39
3

Not natively I believe.

I typically use Stash to do this nowadays. It will give you persistent variables as well as template inheritance so you can do things like this.

Wrapper template

<!DOCTYPE html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8" lang="en"><![endif]-->
<!--[if IE 8]><html class="no-js lt-ie9" lang="en"><![endif]-->
<!--[if gt IE 8]><!--><html class="no-js" lang="en"><!--<![endif]-->

<head>

    <meta charset="utf-8" />
    <link rel="dns-prefetch" href="//use.typekit.com" />

    {if "{exp:stash:not_empty name='st_html_title'}"}<title>{exp:stash:get name="st_html_title"} - Site name</title>{if:else}<title>Site name</title>{/if}

    <meta name="viewport" content="width=device-width" />

    <link rel="shortcut icon" href="{site_url}/favicon.ico" />

    <link rel="stylesheet" media="screen" href="{site_url}/assets/css/screen.css" />

</head>

    <div id="maincontent" role="main">

        {!-- built wisth stash and template partial approach--}
        {exp:stash:get name="content"}

    </div>

</body>
</html>

Partial template

{!-- Layout used --}
{stash:embed:layouts:page}

{!-- Meta data --}
{exp:stash:set name="st_html_title"}Products{/exp:stash:set}

{!-- Build list --}
{exp:stash:set_list name="st_products_list"}
    {exp:channel:entries disable="categories|category_fields|member_data|trackbacks" channel="products" status="open" orderby="date" sort="desc" limit="10"}
        {stash:st_item_title}{title}{/stash:st_item_title}
        {stash:st_item_summary}{cf_product_summary}{/stash:st_item_summary}
    {/exp:channel:entries}
{/exp:stash:set_list}

{!-- Build page content --}
{exp:stash:set name="content"}

    {exp:stash:get_list name="st_products_list" prefix="stashprefix"}

        {if count == "1"}<ul>{/if}
            <li>
                <h2><a href="{st_url}">{st_title}</a></h2>
                <p>{st_item_summary}</p>
            </li>
        {if count == total_results}</ul>{/if}

        {!-- if no results --}
        {if stashprefix:no_results}<p>No Products Found</p>{/if}

    {/exp:stash:get_list}

{/exp:stash:set}

It takes a bit of time to wrap your head around that approach but it is worth it IMHO. Here are a few resources to get you started:

2
  • I can't use {stash:embed} unfortunately. Nov 28 '13 at 7:52
  • Regular embeds would work just fine as well. Mar 11 '14 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.