I am trying to create a dynamic experience where the output is dependant solely on the table. Is there a way to check if a column is empty, and if not, output the column name and column label?
This is how I want the code to work:
<div id="filters" class="button-group">
<button class="button is-checked" data-filter="*">All Channels</button>
{% for row in hubdb_table_rows(673165) %}
{# if column is not empty, add this line #}<button class="button" data-filter="{# add column name #}">{# add column lable #}</button>
{% endfor %}
</div>
Right, so I'm in the process of building a dynamic template across a hubdb MLS listings for boats. Within the boat listing page, it would be beneficial if I could do a dynamic tag for the column name. Then, I would create an "if/then" statement, so if the listing does have data for the specific column, it won't print the column name.
You're saying you want to get a column and print its name for each boat that is for sale. For example the "Role" column in the image above. If the row or "listing" has data in that "Role" column, then print that value in place of the column's name.
Applying that to the image:
For the first row it would print "CFO", and the second it would print "Role"
{% set table = hubdb_table_rows(xxxxxxx) %}
{% set cols = hubdb_table(xxxxxxx).columns %}
{% set colList = cols|map('name') %}
{# Display all Columns in the Table for dev purposes #}
{{ colList }}<br><br>
{# Loop through rows #}
{% for row in table %}
{# Loop through columns in rows #}
{% for col in colList %}
{# If the row has a value #}
{% if row[col] %} {# This if statement may need modified #}
{# Print column name #}
<h6>{{col}}</h6>
{# Print row column value #}
<h3>{{ row[col] }}</h3>
{% endif %}
{% endfor %}
{% endfor %}
EDIT:
Added conditional for printing column names and values
Nov 14, 201710:08 AM - edited Nov 14, 201710:08 AM
Member | Diamond Partner
HubDB - Get and Output Column Name and Label
@roisinkirby, I had to manually input this since it was for a client and there was deadline involved. However, I would still like a solution for this if possible!