Help with conditionally rendering replicator #4937
-
Hi Im pretty new to Statamic and i am stuck on something. My issue is, I currently have a {{REPLICATOR}} wrapped in a div in my antlers.html file and i want to know if i can check if the {{REPLICATOR}} column fields have data from OUTSIDE the {{ REPLICATOR }} antlers. I want to do this because the {{ REPLICATOR}} is wrapped in a div and when there is no data in the column fields the div shows up and takes up space on my page and it interferes with my HERO image. EXAMPLE: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
There are two approaches to take here. The easiest method is to simply check the variable with an {{ if replicator }}
<div>
{{ replicator }}
<!-- Normal Replicator Template Code Here -->
{{ /replicator }}
</div>
{{ /if }} The second is to use the as modifier to move the replicator's sets to a different variable name, allowing us to move the div inside the {{ replicator as="sets" }}
{{ if sets }}
<div>
{{ sets }}
<!-- Normal Replicator Template Code Here -->
{{ /sets }}
</div>
{{ /if }}
{{ /replicator }} |
Beta Was this translation helpful? Give feedback.
There are two approaches to take here. The easiest method is to simply check the variable with an
if
statement.null
or empty arrays will be treated asfalse
, and will cause the code inside the if statement to be ignored:The second is to use the as modifier to move the replicator's sets to a different variable name, allowing us to move the div inside the
{{ replicator }}
. We can then wrap our div inside an if statement (if sets isnull
or empty, it will evaluate to false):