hubDB filtering

SOLVE
Highlighted
Occasional Contributor

Hello,
I am working on a database driven page of training opportunities and running into some issues with filtering. 
The end goal is to have a block of text come up if a certain combination or varibales are not found in the tabl, however I don't want this to repeat for each row in the table I was to only see this message once.

Here is a snippet of current code I am using

{# Finance Tab #}
  <div class="finance-tab padding40tb">
  <h2>Finance</h2>
    {% if table == [] %}
      <p class='align-center'>Sorry, there is an error on this page.</p>
    {% else %}
      <div class="trainings">
        {% rich_text "my_rich_text" label="Enter text here" html="<p>Take some time to get the most out of Church360° Members by attending one of our free training webinars!</p>" %}
{# Finance Webinars #}
      <div class="webinars padding20tb">
        <div class="section-subheader">{% header "my_header" header_tag="h3", overrideable=True, value="Webinars", label="Header" %}</div>
          <div class="table-header">
            <div class="table-header-row">
              <div class="box box1">Title</div>
              <div class="box box2">Date</div>
              <div class="box box3">Time</div>
              <div class="box box4">Link</div>
            </div>
          </div>
          {% for row in table|sort(False, False, 'date') %}
            {% if row["ss-module"].name is containing "Finance" %} 
        			{% if row["type"].name is containing "Webinar" %}
              <div class="boxes">
                <div class="boxes-row">
                  <div class="box box1">{{ row.name }}</div>
                  <div class="box box2"> {{ row.date|datetimeformat('%B %e, %Y') }}</div>
                  <div class="box box3">{{ row.time }}</div>
                  <div class="box box4"><a href="{{ row.url }}" target="_blank" class="cta-green-solid">Register</a></div>
                </div>
              </div>
            {% endif %}
 					{% endif %}
        {% endfor %}
      </div>
{# End Finance Webinars #}
{# Finance Seminars #}
      <div class="seminars padding20tb">
        <div class="section-subheader">{% header "my_header_2" header_tag="h3", overrideable=True, value="Seminars", label="Header" %}</div>
          <div class="table-header">
            <div class="table-header-row">
              <div class="box box1">Title</div>
              <div class="box box2">Date</div>
              <div class="box box3">Time</div>
              <div class="box box4">Link</div>
            </div>
          </div>
        {% for row in table|sort(False, False, 'date') %}
          {% if row["ss-module"].name is containing "Finance" and row["type"].name is containing "Seminar"  %}
            <div class="boxes">
              <div class="boxes-row">
                <div class="box box1">{{ row.name }}</div>
                <div class="box box2"> {{ row.date|datetimeformat('%B %e, %Y') }}</div>
                <div class="box box3">{{ row.time }}</div>
                <div class="box box4"><a href="{{ row.url }}" target="_blank" class="cta-green-outline">View Recording&nbsp;&#9658;</a></div>
              </div>
            </div>
          {% endif %}
        {% endfor %}
      </div>
{# End Finance Seminars #}
      </div>
    {% endif %}
  </div>
{# End Finance Tab #}

Here is a page with this working: http://www-concordiatechnology-org.sandbox.hs-sites.com/shepherds-staff/training?hs_preview=cLkOXaSD...

 

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
Solution
Esteemed Advisor | Partner

@cph_design an  else statement applying the block of text would apply the block of text for each failed iteration.

 

I like to use jquery to show a prexisting div with the message if the elements wrapping the outputed items does not exist:

$(document).ready(function(){
    var container = $('.container_class'),
          items = container.find('.item_class'),
          message = container.find('.message');

    if (items.length <= 0) {
         message.show();
    }
});

 

Need help? Hire Us Here

View solution in original post

Reply
0 Upvotes
2 Replies 2
Highlighted
Solution
Esteemed Advisor | Partner

@cph_design an  else statement applying the block of text would apply the block of text for each failed iteration.

 

I like to use jquery to show a prexisting div with the message if the elements wrapping the outputed items does not exist:

$(document).ready(function(){
    var container = $('.container_class'),
          items = container.find('.item_class'),
          message = container.find('.message');

    if (items.length <= 0) {
         message.show();
    }
});

 

Need help? Hire Us Here

View solution in original post

Reply
0 Upvotes
Highlighted
Top Advisor | Platinum Partner

@cph_design - I like @Jsum answer because of scoping issues within for loops can make it impossible to keep a running total of things outside of a for loop (meaning, you can't set variables or override variables outside of the for loop).

 

But, if you want to count the results, you could use the follow:

from within the loop:

{{loop.length}}

from outside of the loop: 

{{table|sort(False, False, 'date')|length}}

 


If this answer helped, please, mark as solved 😄


tim@belch.io | forms.belch.io | Design your own Beautiful HubSpot Forms; No coding necessary.

 

Drop by and say Hi to me on slack.