CMS Development

marenhogan
Contributor | Gold Partner
Contributor | Gold Partner

Check if data in HubDB row / column in for loop and output comma once

SOLVE

Hello, 

I am pulling from two, separate HubDB Columns: product_type and standard. 

 

product_type is a single select and standard is a multiselect.

 

If there are any rows in "standard", I want to output a comma after product_type. If I put the comma inside of the for loop, it iterates a new comma every time. 

 

I want to output one comma after product_type, even if there are multiple standard items selected (the loop already outputs a comma after these items if there are more than one)

 

<div class="tagss">
{{ row.product_type.name }},
{% for category in row.standard %}
{{ category.name }}{% if not loop.last %},{% endif %}
{% endfor %}
</div>

 In my screenshot example, you'll see a comma after "Modules". Because there is no "standard" selected in HubDB, I don't want that comma to output. 

 

Thanks! 

0 Upvotes
1 Accepted solution
marenhogan
Solution
Contributor | Gold Partner
Contributor | Gold Partner

Check if data in HubDB row / column in for loop and output comma once

SOLVE

Thanks for the help! 

That didn't work, but it got me headed in the right direction. I updated the code to : 

{% if row.standard != null %}, {% endif %}

because I only wanted the comma to output if the standard column was empty. And I need to check the row/column for that. 

Thanks! 

View solution in original post

0 Upvotes
2 Replies 2
Anton
Thought Leader | Partner
Thought Leader | Partner

Check if data in HubDB row / column in for loop and output comma once

SOLVE

Hi @marenhogan

 

try  

{% if category.name == null %}, {% endif %}

 (you might need play with some options here)

 

best, 

Anton

Anton Bujanowski Signature
marenhogan
Solution
Contributor | Gold Partner
Contributor | Gold Partner

Check if data in HubDB row / column in for loop and output comma once

SOLVE

Thanks for the help! 

That didn't work, but it got me headed in the right direction. I updated the code to : 

{% if row.standard != null %}, {% endif %}

because I only wanted the comma to output if the standard column was empty. And I need to check the row/column for that. 

Thanks! 

0 Upvotes