Twig for Loops and Inline if Syntax

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:07
    with Leanna Pelham
  • 0:09
    Let's give ourselves a challenge.
  • 0:12
    Our products are printing out a bit weird right now, because they're
  • 0:15
    floating but not breaking correctly.
  • 0:18
    To fix this, we need to wrap every three
  • 0:20
    products in their very own row div.
  • 0:24
    To do this, we can use a divisible by test
  • 0:26
    to see if the item number we're on is divisible by 3.
  • 0:54
    When we refresh, Twig is sad because the loop
  • 0:57
    number variable is undefined.
Loading ...

Twig for Loops and Inline if Syntax

Loading...

Our products are printing out a bit weird right now because they’re floating, but not breaking correctly. To fix this, we need to wrap every three products in their very own row. In this tutorial, you will use a "divisibleby" test to see if the item number we’re on is divisible by three, and then loop through them. We'll also clean up our if statement for our background color, by implementing an inline if syntax.

Downloads: 
Log in or sign up to download companion files.

Additional resources:
There are no resources for this video. If you believe there should be, please contact us.