CMS Development

JLanfear
Membro

HubDB Selection Field

resolver

Hi,

 

I am having some trouble with the HubDB Selection field, my basic idea is when we add new data to the HubDB we select a 'Format' that format can either be a download, a course, a video etc...  What I am wanting to do is display an icon depending on what has been selected in that column.

 

I'm trying to loop through the 'format' column for each row, check what the selection is and if it's 'Download' display a download icon, and so on and so forth.

 

Any help would be really appreciated. Thank you!

 

 

0 Avaliação positiva
1 Solução aceita
LucBenayoun
Solução
Participante

HubDB Selection Field

resolver

Okay that's what I was thinking. By copy/paste my code you're looping inside an existing loop your created before. Replace all HubL code with this:

{% set table = hubdb_table_rows(3411941, queryparam) %}
<div class="rlpp-grid rlpp-grid-3col">
  {% if table == [] %}
  <p class='align-center' style="color: #2a2a2a; width: 100%;">Sorry, no listings found for that Search. Try changing your filter and search again.</p>
  {% else %}
  {% for row in table %}
  <div class="resource-listing">
    <a href=" {{ row["link"] }} " target="_blank" style="color: #fff;">
      <div class="resource--format__icon">
        {% if row.format.name|lower == "download" %}
        <i class="fas fa-download">Icon</i>
        // Other code like name and so on
        {% else %}
        // Other code like name and so on
        {% endif %}
      </div>
    </a>
  </div>
  {% endfor %}
  {% endif %}
</div>

 

Let me know! 🔥

Exibir solução no post original

8 Respostas 8
LucBenayoun
Participante

HubDB Selection Field

resolver

Hey! 

 

From what I understand, you currently set a "Format" field which is a dropdown select. From this field, you want to retrieve what is the data selected from this field and show an icon if this is the case right? 

 

Well, follow this kind of logic and it should work 🙂 

{% set table = hubdb_table_rows(module.hubdbtable_field) %}
{% for row in table %}
{% if row.format.name|lower == "download" %}
// If format = download
{% else %}
// If format != download
{% endif %}
// Other code
{% endfor %}


Example with some HTML: 

{% set table = hubdb_table_rows(module.hubdbtable_field) %}
<div class='container'>
  <div class='row-fluid'>
    <h1>HubDB Example</h1>
  </div>
</div>
<div class='container'>
  <div class='row-fluid'>
    {% for row in table %}
    <div class='span4 columns'>
      <div class='category'>
        {% if row.format.name|lower == "download" %}<i class='download'>Icon</i>{% else %}{{ row.format.name }}{% endif %}
      </div>
      <h2>{{ row.name }}</h2>
    </div>
    {% endfor %}
  </div>
</div>

 

Cheers 🙂

0 Avaliação positiva
JLanfear
Membro

HubDB Selection Field

resolver

Don't think that works, think you are on the right path though, 

 

basically, I have a column in my hubdb where when we add new content you select either: Download, Article, Podcast, Video, Website, Course or Interview. On the resource (see below) I want to print an icon depending on what is selected.

 

I think the if condition to see if the name is download is right but that just prints 7 download icons rather than one because there are seven rows that have selected download.

JLanfear_0-1617970688177.png

 

0 Avaliação positiva
LucBenayoun
Participante

HubDB Selection Field

resolver

I'm not sure to fully understand. I tested with a HubDB, here are my screenshots. 

 

Capture d’écran 2021-04-09 à 14.36.36.png

 

Capture d’écran 2021-04-09 à 14.36.19.png

 

Tell me what I'm missing and I'll be happy to help! 😉

0 Avaliação positiva
JLanfear
Membro

HubDB Selection Field

resolver

Sorry man, it's probably me, when I input your code this is what I get.

JLanfear_0-1617976517288.png

Am I supposed to change some values to my own? Again sorry not well versed in this department.

0 Avaliação positiva
LucBenayoun
Participante

HubDB Selection Field

resolver

I think it should be better that you paste you module code in here so I can take a look but you're probably looping in another loop 🙂

 

0 Avaliação positiva
JLanfear
Membro

HubDB Selection Field

resolver

This is the section of code for the resource listing part of the module, your addition is in bold.

 

<div class="resource-body">
{% set table = hubdb_table_rows(3411941, queryparam) %}
<div class="rlpp-grid rlpp-grid-3col">
{% if table == [] %}
<p class='align-center' style="color: #2a2a2a; width: 100%;">Sorry, no listings found for that Search. Try changing your filter and search again.</p>
{% else %}
{% for row in table %}

<div class="resource-listing">

<a href=" {{ row["link"] }} " target="_blank" style="color: #fff;">

<div class="resource--format__icon">

{% set table = hubdb_table_rows(module.hubdbtable_field) %}
{% for row in table %}
{% if row.format.name|lower == "download" %}
<i class="fas fa-download"></i>
{% else %}

{% endif %}

{% endfor %}


</div>

<div class="image-container"><img src="{{ row["image"].url}}"></div>
<div class="category-display-container" style="color: #dd083b;">{{ row["type"].name }}</div>
<h4 style="color: #2a2a2a; text-align: center;">{{ row["title"] }}</h4>
<p style="color: #2a2a2a; text-align: center;">{{ row["description"] }}</p>

<div class="view-button-container">
<button class="view-button">View Resource</button>
</div>

</a>
</div>

{% endfor %}
{% endif %}
</div>

<div class="loadmore-container">
<a href="#" id="loadMore">Load More</a>
</div>


</div>

 

 

 

0 Avaliação positiva
LucBenayoun
Solução
Participante

HubDB Selection Field

resolver

Okay that's what I was thinking. By copy/paste my code you're looping inside an existing loop your created before. Replace all HubL code with this:

{% set table = hubdb_table_rows(3411941, queryparam) %}
<div class="rlpp-grid rlpp-grid-3col">
  {% if table == [] %}
  <p class='align-center' style="color: #2a2a2a; width: 100%;">Sorry, no listings found for that Search. Try changing your filter and search again.</p>
  {% else %}
  {% for row in table %}
  <div class="resource-listing">
    <a href=" {{ row["link"] }} " target="_blank" style="color: #fff;">
      <div class="resource--format__icon">
        {% if row.format.name|lower == "download" %}
        <i class="fas fa-download">Icon</i>
        // Other code like name and so on
        {% else %}
        // Other code like name and so on
        {% endif %}
      </div>
    </a>
  </div>
  {% endfor %}
  {% endif %}
</div>

 

Let me know! 🔥

JLanfear
Membro

HubDB Selection Field

resolver

 

Thank man you did it! Really appreciate your help, you're a lifesaver!

JLanfear_1-1617979063280.png

 

0 Avaliação positiva