CMS Development

Daniel_eon
Participant

Addressing looped items in nested groups

SOLVE

Hi everyone,

 

I am trying to reverse-engineer some modules in the Design Manager that an agency did for us and make changes to them, so I am not too familiar with HubL yet and am reading through the developer documentation as I go.

 

This one is a carousel module, based on the bootstrap carousel. To add more slides, the carousel-item-class is looped. I added some optional CSS gradient overlay controls to the looped image slide, which works fine.

 

 {% for item in module.slide %}
      
      <div class="carousel-item-{{loop.index}} carousel-item{% if loop.first %} img-fluid active{% endif %}" data-interval="{{ item.slide_duration *1000 }}" style="background-image: 
        {% if item.overlay_gradient %}
          linear-gradient(
          {% if item.gradient_direction != 'custom' %}  
             {{ item.gradient_direction }}
          {% else %} 
             {{ item.custom_direction }}deg
          {% endif %}, rgba({{ item.gradient_first_color.color|convert_rgb }}, {{ item.gradient_first_color.opacity / 100 }}), rgba({{ item.gradient_second_color.color|convert_rgb }}, {{ item.gradient_second_color.opacity / 100}})),
        {% endif %}
          url({{ item.image_slider.src }});background-size: cover;background-position: center;">
        {% if item.link %}<a class="carousel-item-link" href="{{item.link}}"></a> {% endif %} 

The looped carousel-item is put into a module subgroup called "slide". Within this slide subgroup, I would like to create another subgroup "gradient_settings" (hence a nested group) for just the gradient controls. But then, I don't know how to correctly address the items in the nested group with HubL. I tried various combinations, e.g.

  • item.gradient_settings.gradient_first_color.color
  • item.slide.gradient_settings.gradient_first_color.color
  • module.item.slide.gradient_settings.gradient_first_color.color
  • module.slide.gradient_settings.gradient_first_color.color

etc., but none of these work.

 

How do I need to address items in HubL with this hierarchy?

Module - looped "slide group" - Nested "gradient_settings group" within the looped "slide group" - single item?

 

Thanks 🙂

0 Upvotes
1 Accepted solution
vish891
Solution
Member

Addressing looped items in nested groups

SOLVE

Hey

 

Had created the same setup and i could access it with the code i sent.

 

Screen Shot 2020-07-15 at 7.51.22 PM.png

View solution in original post

0 Upvotes
8 Replies 8
MGheibi
Participant | Platinum Partner
Participant | Platinum Partner

Addressing looped items in nested groups

SOLVE

Hello

you can use:

{% for item in module.FirstStepFieldGroup.SecondStepFieldGroup %}

{{item}} that you need

{% endfor %}

 

 

0 Upvotes
vish891
Member

Addressing looped items in nested groups

SOLVE

Pls try this

 

item.gradient_first_color.color

0 Upvotes
Daniel_eon
Participant

Addressing looped items in nested groups

SOLVE

Hi vish,

 

thanks for the suggestion. This is how the items are currently addressed in the code, and this works fine. But that stops working once you put the items in a nested group.

0 Upvotes
vish891
Solution
Member

Addressing looped items in nested groups

SOLVE

Hey

 

Had created the same setup and i could access it with the code i sent.

 

Screen Shot 2020-07-15 at 7.51.22 PM.png

0 Upvotes
John
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Addressing looped items in nested groups

SOLVE

a screenshot of the module fields might help us wrap our head around what you are asking



I like kudos almost as much as cake – a close second.

Daniel_eon
Participant

Addressing looped items in nested groups

SOLVE

Hi John,

 

thanks for the reply. So here is what the module structure /hierarchy looks like currently and which works with the code posted above:

module_current.jpg

And here is what I would like to do. As soon as I move controls in a nested group, the above code no longer works, as the path to the controls changes.

module_subgroup.jpg

0 Upvotes
sharonlicari
Community Manager
Community Manager

Addressing looped items in nested groups

SOLVE

Hey @Daniel_eon 

 

Thank you for the information provided. I'll tag a few experts that can share their knowledge with you.

 

Hey @FabianRichter @John @DavidFJones could you please share your thoughts with @Daniel_eon

 

Thanks

Sharon


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !




Daniel_eon
Participant

Addressing looped items in nested groups

SOLVE

Hi Sharon,

 

thank you, much appreciated 🙂

0 Upvotes