0

I ran into a situation in which I need to pass a Grid field via embed. Is there a good way of doing this? I won’t know how many entries (rows) have been entered. I have set a max to five (5) and there are three (3) columns.

Simplified Template Added

In my primary template, I have a simple call to embed the footer like this:

{embed="Footer/index"}

That is just a router template.

Footer Router Template

{exp:channel:entries 
    channel="footer" 
    limit="1" 
    disable='categories|member_data|pagination' 
}

    {!-- FIND THE TEMPLATE CHOSEN --}
    {exp:query 
        sql="SELECT template_name FROM exp_templates WHERE template_id = '{footer_layout}' "
    }
        {embed="Footer/{template_name}" 
            banner="{banner_text}" 
            news_head="{newsletter_subscription_header}" 
            news_intro="{newsletter_lead_in_copy}" 
            twitter_head="{twitter_feed_header}" 
            contact_head="{contact_header}" 
            posts_head="{recent_posts_header}"
            work_head="{recent_work_header}"
        }
    {/exp:query}

{/exp:channel:entries}

(This is where I would like to embed the Grid fields if possible to kep from deep nested templates)

In the entry template, I am using Better Pages to allow them to choose a layout. There is one layout that when chosen, allows them to add up to 4 columns of mini navigational elements. This is where the Grid fields come into play.

There are four fields that display for this page template selection. Each has the following 2 Grid fields:

The first is an options grid field {column_1_options}. 1 row 3 columns. Text 'Header', Dropdown 'Automatic' or 'Manual', and Dropdown 'Blog' or 'Portfolio' or 'Twitter'.

The second is a links grid field {column_1_links} for them to populate the navigational elements if they choose 'Manual' in the Dropdown above. It contains 0-5 Rows with 2 Text Input columns named 'Link' and 'Text'.

Currently I use stash lists to gather these like this:

{exp:channel:entries
    channel="footer"
    limit="1"
    disable="categories|member_data|pagination"
}
    {column_1_options}
        {exp:stash:col_1_head}{column_1_options:column_1_header}{/exp:stash:col_1_head}
        {exp:stash:col_1_method}{column_1_options:automatic_or_manual}{/exp:stash:col_1_method}
        {exp:stash:col_1_section}{column_1_options:section_for_automatic_links}{/exp:stash:col_1_section}
    {/column_1_options}
    {exp:stash:set_list name="column_1_links" parse_tags="yes"}
        {column_1_links}
            {stash:href}{column_1_links:link}{/stash:href}
            {stash:text}{column_1_links:text}{/stash:text}
        {/column_1_links}
    {/exp:stash:set_list}
{/exp:channel:entries}

This is in a stash template that I call in the header of my primary templates like this:

{!-- STASH SITE SETTINGS --}
    {stash:embed:partials:site_variables process="start" replace="yes" parse="yes"}
{!-- /STASH SITE SETTINGS --}

In my footer template for the one they choose (The one with these options), I display their choices by pulling out the stash variables like this:

            <div class="row">
                <div class="col-md-3">
                    <h5>{if "{exp:stash:get name='col_1_head'}" != ""}{exp:stash:get name='col_1_head'}{/if}</h5>
                    {if "{exp:stash:col_1_method}" == "Manual"}
                        <ul class="list icons list-unstyled">
                            {exp:stash:get_list name="column_1_links"}
                                <li><i class="icon icon-caret-right"></i> <a href="{href}">{text}</a></li>
                            {/exp:stash:get_list}
                        </ul>
                    {if:else}
                        {if "{exp:stash:get name='col_1_section'}" == "Blog"}
                            <ul class="list icons list-unstyled">
                                {exp:channel:entries
                                    channel="blog_post"
                                    limit="5"
                                }
                                    <li><i class="icon icon-caret-right"></i> <a title="{title}" href="{title_permalink='blog/entry'}">{exp:eehive_hacksaw words="5" append = "..." allow = "<b><a><p>"}{title}{/exp:eehive_hacksaw}</a></li>
                                {/exp:channel:entries}
                            </ul>
                        {/if}
                        {if "{exp:stash:get name='col_1_section'}" == "Portfolio"}
                            {exp:channel:entries
                                channel="portfolio_item"
                                limit="5"
                            }
                                <li><i class="icon icon-caret-right"></i> <a title="{title}" href="{title_permalink='portfolio/item'}">{exp:eehive_hacksaw words="5" append = "..." allow = "<b><a><p>"}{title}{/exp:eehive_hacksaw}</a></li>
                            {/exp:channel:entries}
                        {/if}
                        {if "{exp:stash:get name='col_1_section'}" == "Twitter"}
                            <div id="tweet" class="twitter" data-account-id="{exp:stash:get name='twitter-id'}">
                            <p>Please wait...</p>
                        {/if}
                    {/if}
                </div>
                ...
            </div>

I would just like to be able to better utilize core features when available. I am always wanting to expand my knowledge of how to better build and simplify sites. :)

2
  • Can you add a bit more context of what you're wanting to accomplish? What your data contains, and your desired end result. I have a feeling an embed isn't the right solution for you here, but need to more details to make that call. Commented Aug 22, 2014 at 18:08
  • Hey Derek. Yes. This is for a set of user defined settings for a navigational feature. The first grid is the options Grid field. This contains a Header, Select Dropdown for a setting, and a second Select Dropdown for another setting. The second Grid field consists of the option for 5 links to be built using 2 text fields. One for the URL and one for the Text to display. The links will be displayed determined by one of the Select Dropdowns in the first Grid field. I am able to achieve what I need by using the Stash plugin. I was just trying to keep it native.
    – W3bGuy
    Commented Aug 22, 2014 at 18:20

1 Answer 1

1

So the channel entries tag that outputs this lives somewhere other than where your navigation is built, I'm assuming. Without seeing your template I couldn't say for sure, but this sounds like a great case for using a template layout. If you update your question with a simplified version of your templates, I could provide a more specific example, but the documentation covers what you would need: the layout wrapper, and layout variables.

1
  • Derek, I have added some template code and info to try to help explain. Let me know if this helps.
    – W3bGuy
    Commented Aug 23, 2014 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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