How to compare values in tags dynamically? #5194
-
Hi - pretty new to statamic, let me know if I'm not using it properly. I'm trying render html based on the value of something in a collection. e.g.
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You can't use JavaScript in Antlers tags because it's rendered before it gets sent to the browser. JavaScript doesn't have a chance to touch it. I guess you could output everything through Antlers and use some logic in your Javascript to display the right one. Using Alpine.js as an example here. This Antlers code...
would render...
Then Alpine would display the right one. Although something tells me this is also not a great solution. Maybe more details about what you're doing would be helpful and you could get a different suggestion. |
Beta Was this translation helpful? Give feedback.
You can't use JavaScript in Antlers tags because it's rendered before it gets sent to the browser. JavaScript doesn't have a chance to touch it.
I guess you could output everything through Antlers and use some logic in your Javascript to display the right one.
Using Alpine.js as an example here. This Antlers code...
would render...
Then Alpine would display the right one.
Although something tells me this is also not a great solution. Maybe more details about what you're doing would be he…