Hello! I'm trying to implement an "if/then" statement using HubL and I can't seem to get it to work right.
Essentially, I'm trying to say "if this row in this column has no information in it, don't show the div it's being contained in". However, whether it has information in it or not, it's hiding the containing div. However, the top section (shown in the attached image) works just fine, so no issues there.
I'm sure my code is just off a bit, so can someone please help me out here?
@djsteink where is the "why_we_love_partner" variable being set? I don't see it anywhere so the if statement will never work if the variable doesn't ever exist.
I'll lay the user case out for you. There is a table in HubDB that's housing all the information for each of our partners that's basically set up like so:
Partner name | About the partner | Why we love partner
From here, there are 2 pages. Page one lists out all the partners. A user clicks on a partner and they are brought to the Partner Details page which gives them all the info on whichever partner they clicked into.
Let's say the user clicks Partner 1. I'm trying to say, if the "Why we love partner" column for Partner 1 has no information, hide the div containing the "Why we love partner" section. If the cell has information, show the div.
Any ideas as to how I'd go about writing this out?
@djsteink your if statement needs to be inside the for loop in order to work. e.g.:
{% for row in table %}
{% if row.why_we_love_partner %}
this text will only show if the "why we love partner" content exists in this row.
{% endif %}
{% endfor %}
Maybe I'm misreading what you're saying, but that wouldn't seem to make much sense, as then if the table is undefined, nothing shows; if it's not, then it shows the content I want to see only when the element is undefined and the content I want displaying if the element is defined.
I also tried it for kicks and it still doesn't work.
Maybe I'm not understanding what you're saying. How would you write it?