CMS Development

djsteink
Member

HubL Code Help!

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?

 

Screen Shot 2019-08-14 at 11.11.39 AM.png

0 Upvotes
6 Replies 6
stefen
Key Advisor | Partner
Key Advisor | Partner

HubL Code Help!

@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.

Stefen Phelps, Community Champion, Kelp Web Developer
0 Upvotes
djsteink
Member

HubL Code Help!

Hey @stefen @ashleyidesign , "why_we_love_partner" is a column in a HubDB table.

 

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

_____________|______________________________|__________________________________

Partner 1          |  Partner 1 is a company.                |  We love them because they're great.

_____________|______________________________|__________________________________

Partner 2          |  Partner 2 is a company too.         |  We love them because they're cool.

_____________|______________________________|__________________________________

 

 

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?

 

Thanks!

0 Upvotes
stefen
Key Advisor | Partner
Key Advisor | Partner

HubL Code Help!

@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 %}

 

 

Stefen Phelps, Community Champion, Kelp Web Developer
djsteink
Member

HubL Code Help!

@stefen thanks, but that didn't work either 😕

0 Upvotes
ashleyidesign
Top Contributor | Partner
Top Contributor | Partner

HubL Code Help!

I would rewrite slightly so that the stuff you want to show when the field is undefined is under else, instead of if.

0 Upvotes
djsteink
Member

HubL Code Help!

Hi @ashleyidesign ,

 

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?

0 Upvotes