We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Grid entry image repeating x 3

How Do I?

_SiD_'s avatar
_SiD_
17 posts
one year ago
_SiD_'s avatar _SiD_

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.

       
Rob Allen's avatar
Rob Allen
3,105 posts
one year ago
Rob Allen's avatar Rob Allen

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.

       
_SiD_'s avatar
_SiD_
17 posts
one year ago
_SiD_'s avatar _SiD_

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?

       
_SiD_'s avatar
_SiD_
17 posts
one year ago
_SiD_'s avatar _SiD_

Got it. I check all the fields again

{entry_bg_banr_image}

Isn’t part of the Grid Field!!! Wrapping it in the Grid tags sent it on a wild goose chase. A Grid tag was swapped out for a this new field at some point.

What a dick!

Thanks again, Rob – you sent me on the right path.

S

       
Rob Allen's avatar
Rob Allen
3,105 posts
one year ago
Rob Allen's avatar Rob Allen

Glad you got it sorted!

? 1
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.