CMS Development

Amit_95
参加者 | Platinum Partner
参加者 | Platinum Partner

Using HUBL for calculated inline CSS

I have a tabbed module which by default, shows 6 products. However, when another tab is clicked, it shows 4 products. I.e.

  1. Tab Compare all products shows six items.
  2. Tab Business only shows four items (because there's only four business products).

 

Based on this, I'm trying to set the width of the container based on how many items are in its container. I have the PHP for it, but stuggling to convert it into HubL:

 

$productWidth = 'calc((100% / ' . $numberOfProducts . ') - (5em / ' . $numberOfProducts . ') - 4px)';

HubL:

 

 {% for item in module.products %}

      <!-- Check how many products exist in total (6) -->
      {% set numberOfProducts = loop.length %}
      
      <!-- Check how many business products exist (4) -->
      {% if item.this_is_a_homeowner_product %}
        {% set numberHomeowner == loop.index %} 
      {% endif %}
    
      {% set first_calc = (100 / numberOfProducts)  %}
      {% set second_calc = ('75' / numberOfProducts) %}
      {% set calc = first_calc - second_calc %}

      {% set productWidth =  (first_calc - second_calc) - 4px %}

      <div class="containerProducts" style="width:{{ productWidth }};"> </div>

{% endfor %}

 

 

0 いいね!
1件の返信
MFrankJohnson
ソートリーダー

Using HUBL for calculated inline CSS

Have you tried to remove the single quotes, so your code reads ??

 {% set second_calc = (75 / numberOfProducts) %}

- see Operators & expression tests

 

Note: Please search for recent posts as HubSpot evolves to be the #1 CRM platform of choice world-wide.

 

Hope that helps.

 

Be well,
Frank


www.mfrankjohnson.com
0 いいね!