I have a banner at the top of a page. I want to insert a background image into the banner data-background.
I have a Grid Field containing lots of different content for the page. One of the fields is called {entry_bg_banr_image} I am attempting to pull the image from that field into the background.
Here’s what it looks like…
{exp:channel:entries channel="name"}
{heads_and_paras}
<section class="small-section bg-dark-alfa-30 bg-scroll light-content" data-background="{entry_bg_banr_image}" id="home">
{/heads_and_paras}
…more code filling the banner.
</section>
{/exp:channel:entries }It’s looping through 3 times pulling through the same image each time and producing
<section class="… .jpg">3 times - without getting to the closing…
`
</section>However, there is only one image in this field.
Is this a setting on the Grid field or something else? Stumped.
It’s looping multiple times because you have more than one grid row.
To solve it you’d need to limit the output to the row that has the image, try something like this:
{heads_and_paras limit="1" search:entry_bg_banr_image="not IS_EMPTY"}
{if count == "1"}
<section class="small-section bg-dark-alfa-30 bg-scroll light-content" data-background="{heads_and_paras:entry_bg_banr_image}" id="home">
{/if}
{/heads_and_paras}The limit parameter tells EE to only output one row, and the search: parameter tells EE to only output a row where an image exists. The if count conditional limits the section tag to be output once if there are multiple images in the grid.
I can’t figure out how it has 3 rows? Or how to confirm?
Already tried a conditional with no effect:
{heads_and_paras}
{if count == 1}
<section class="small-section bg-dark-alfa-30 bg-scroll light-content"data-background="{entry_bg_banr_image}"id="home">
{/if}
{/heads_and_paras}But not as you suggested.
Update:
adding
limit="1" search:entry_bg_banr_image="not IS_EMPTY"Solved the problem, Rob. Super.
Now – any idea how the additional rows they got there?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.