Skip to content

Instantly share code, notes, and snippets.

@croxton
Created November 25, 2015 10:09
Show Gist options
  • Save croxton/7f7d59a4a44bd70cfc75 to your computer and use it in GitHub Desktop.
Save croxton/7f7d59a4a44bd70cfc75 to your computer and use it in GitHub Desktop.
Nesting EE blocks with Stash
{project_gallery}

	{!-- section --}
	{bk_gallery_section}

		<section class="gallery">

			{!-- save count of current section --}
			{exp:stash:set_value name="section_index" value="{blocks:count:of:type}" random}

			{if heading}
			<header>
				<h2 class="gallery-title">{heading}</h2>
			</header>
			{/if}

			{!-- background image --}
			{if bg_img}
			<div class="gallery-bg-img">
				<img src="{bg_img}" alt="">
			</div>
			{/if}

			<div class="wrap">

				{!-- child blocks --}
				{exp:stash:get name="gallery_{blocks:count:of:type}" process="end" random}
				
			</div>

		</section>

	{/bk_gallery_section}

	{!-- copy --}
	{bk_copy}
		{exp:stash:append name="gallery_{exp:stash:section_index random}" parse="inward" random}
		<div class="gallery-copy">{copy}</div>
		{/exp:stash:append}
	{/bk_copy}

	{!-- image --}
	{bk_img}
		{exp:stash:append name="gallery_{exp:stash:section_index random}" parse="inward" random}
		<figure class="gallery-img">
			<ul>
				{img}<li><img src="{url}" alt="{alt_text}"></li>{/img}
			</ul>
			{if caption}
			<figcaption>{caption}</figcaption>
			{/if}	
		</figure>
		{/exp:stash:append}
	{/bk_img}

	{!-- video --}
	{bk_video}
		{exp:stash:append name="gallery_{exp:stash:section_index random}" parse="inward" random}
		<figure class="gallery-video">
			{video:embed youtube:showinfo="0" vimeo:title="0" vimeo:byline="0" vimeo:badge="0" vimeo:portrait="0" vimeo:color="569AE7"}
			{if caption}
			<figcaption>{caption}</figcaption>
			{/if}
		</figure>
		{/exp:stash:append}
	{/bk_video}

{/project_gallery}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment