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. :)