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

Fluid field - check if the field is the last

How Do I?

deswork's avatar
deswork
122 posts
3 years ago
deswork's avatar deswork

I have a fluid field called page content with a number of fields added to it.

What I want to do is add margin bottom a row if it’s not the last one, see below.

{page_content} 

{page_content:text}
 <div class="row{if ! page_content:last} mb-5{/if}">
  <div class="col-12 paragraph-text">
   {content}
  </div>
 </div>
{/page_content:text}
 
{page_content:related_video}
 <div class="row{if ! page_content:last} mb-5{/if}">
  <div class="col-12">
  {content}  
   <div class="ratio ratio-16x9 mb-0">
    {if !content:vimeo_hosted}
    <iframe class="embed-responsive-item" src="https://www.youtube.com/embed/{content:video_embed_code}?rel=0{if content:video_autoplay}&autoplay=1&mute=1{/if}{if content:video_loop}&loop=1&playlist;={content:video_embed_code}{/if}"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
    {if:else}
    <iframe class="embed-responsive-item" src="https://player.vimeo.com/video/{content:video_embed_code}{if content:video_loop}?loop=1{/if}" width="640" height="360" frameborder="0"></iframe>
    {/if}
   </div>  
   {if content:overview}
   <div class="small text-center mt-3 mb-0 description paragraph-text">
   {content:overview}
   </div>
   {/if}
  {/content}
  </div>
 </div>
{/page_content:related_video}

{/page_content}

What I have seems to work unless the last field is a relationship field.

Am I misunderstanding how the last variable works?

Thanks

       
magdalenapopp's avatar
magdalenapopp
4 posts
one year ago
magdalenapopp's avatar magdalenapopp

Hello @ minecraftle game, In your template code, you are trying to add a “mb-5” class to the “row” element if it’s not the last row within the “page_content” fluid field. However, it seems that you are using the incorrect variable to check if it’s the last row. You can try using “{page_content:row:count}” and “{page_content:total_rows}” within the conditional statement, you can compare the current row count with the total number of rows in the “page_content” field. If they are not equal, it means it’s not the last row, and the “mb-5” class will be added to the “row” element.

       
Curtis Wilder's avatar
Curtis Wilder
1 posts
one year ago
Curtis Wilder's avatar Curtis Wilder

Add a bottom margin to each row in the page content, except the last one.

javascript

const rows = document.querySelectorAll(‘.page-content-row’); rows.forEach((row, index) => { if (index !== rows.length - 1) { row.style.marginBottom = ‘20px’; } });

       

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.