Skip to content

Help with conditionally rendering replicator #4937

Answered by JohnathonKoster
suarez2145 asked this question in Q&A
Discussion options

You must be logged in to vote

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 as false, and will cause the code inside the if statement to be ignored:

{{ 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 }}. We can then wrap our div inside an if statement (if sets is null or empty, it will evaluate to false):

{{ replicator as="sets" }}
    {{ if sets }}
        <div>…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@suarez2145
Comment options

Answer selected by suarez2145
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants