# Passing section context data to nested group in custom module

**URL:** <https://community.hubspot.com/t/passing-section-context-data-to-nested-group-in-custom-module/64305>\
**Category:** CMS Development\
**Created:** [September 1, 2022, 7:50pm UTC](https://community.hubspot.com/t/passing-section-context-data-to-nested-group-in-custom-module/64305 "2022-09-01T19:50:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![josephLayden](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/josephlayden/32/68653_2.png) [@josephLayden](https://community.hubspot.com/u/josephLayden)\
**Post date:** [September 1, 2022, 7:50pm UTC](https://community.hubspot.com/t/passing-section-context-data-to-nested-group-in-custom-module/64305/1 "2022-09-01T19:50:52Z")

</div>

I have created a section with context and am trying to pass data to the custom module, but cannot figure out the Hubl to access grouped fields. Example outlined below, where there is a repeater group inside my custom module and I want to pass a unique image field or link to display in the template. For the section heading I can use a string easily, but I cannot figure out the groups.

Custom Module Fields:

\> Section Heading

\> Section Description

\> Card (Repeater Group)

\>\> Card Title

\>\> Card Image

\>\> Card Link

{% dnd\_section %}  
{% dnd\_column %}  
{% dnd\_row %}  
{% dnd\_module path=“../../modules/cardScroll.module” %}  
{% module\_attribute ‘variant’ %}{{ context.variant || ‘gradient’ }}{% end\_module\_attribute %}  
{% module\_attribute ‘background\_color’ %}{{ context.background\_color || ‘light’ }}{% end\_module\_attribute %}

TODO not working below  
{% module\_attribute ‘card\_content.image\_field’ %}{{ context.image || get\_asset\_url(‘../images/blank-page-banner.png’) }}{% end\_module\_attribute %}  
{% end\_dnd\_module %}  
{% end\_dnd\_row %}  
{% end\_dnd\_column %}  
{% end\_dnd\_section %}

---

<div class="post-metadata">

**Author:** ![LeeBartelme](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/leebartelme/32/95647_2.png) [@LeeBartelme](https://community.hubspot.com/u/LeeBartelme)\
**Post date:** [September 2, 2022, 3:44pm UTC](https://community.hubspot.com/t/passing-section-context-data-to-nested-group-in-custom-module/64305/2 "2022-09-02T15:44:35Z")

</div>

The only way I was able to get this to work was to apply attributes at the top level. Therefore, the value of card\_content must be a json string with the values needed. So in your example something like this should work:

```lia-code-sample
{# Basic Example #}
{% module_attribute 'group_name' %}
{ field_name: 'field value' }
{% end_module_attribute %}

{# Your use case #}
{% module_attribute 'card_content' %}
{ image_field: {{ context.image || get_asset_url('../images/blank-page-banner.png') }} }
{% end_module_attribute %}

```

I got this working in my test using the first code example above. I’m not 100% sure of what HubL is acceptable inside dnd areas or module\_attribute areas. I feel like dot notation should work like you tried, but I couldn’t get it to work witout just assigning the parent group a json value.

---

<div class="post-metadata">

**Author:** ![josephLayden](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/josephlayden/32/68653_2.png) [@josephLayden](https://community.hubspot.com/u/josephLayden)\
**Post date:** [September 2, 2022, 4:12pm UTC](https://community.hubspot.com/t/passing-section-context-data-to-nested-group-in-custom-module/64305/3 "2022-09-02T16:12:51Z")

</div>

I tried the JSON as a string and as object literal but end up with two warnings and the module not rendering fully.

is\_json is false but this value looks like a JSON object.

AND

Invalid value for field [card\_content] in module [cardScroll]: “Value for field with an occurrence must be an array”

---

<div class="post-metadata">

**Author:** ![LeeBartelme](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/leebartelme/32/95647_2.png) [@LeeBartelme](https://community.hubspot.com/u/LeeBartelme)\
**Post date:** [September 2, 2022, 4:24pm UTC](https://community.hubspot.com/t/passing-section-context-data-to-nested-group-in-custom-module/64305/4 "2022-09-02T16:24:33Z")

</div>

So if card\_content is a repeater the object would need to be an array instead of a single object.

```lia-code-sample
{# Single Item in Group #}
{% module_attribute 'group_name' %}
[{ field_name: 'field value' }]
{% end_module_attribute %}

{# Multiple Items in Group #}
{% module_attribute 'group_name' %}
[
{ field_name: 'field value 1' },
{ field_name: 'field value 2' }
]
{% end_module_attribute %}

```

 ![image.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/6/d/6d321a5669c413f633211a454ad8491d887415f1.png)

 ![image.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/c/e/ce79bf9997b8bc78ce28cdd62a2953c482b09df7.png)

The above code is working in my instance where the group is named ‘group’ and the field is named ‘text’ and group is a repeater.

---

<div class="post-metadata">

**Author:** ![jaymewelch](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaymewelch/32/41908_2.png) [@jaymewelch](https://community.hubspot.com/u/jaymewelch)\
**Post date:** [July 31, 2024, 5:23pm UTC](https://community.hubspot.com/t/passing-section-context-data-to-nested-group-in-custom-module/64305/5 "2024-07-31T17:23:43Z")

</div>

The question I believe the OP and I both have is how do you set context on the multiple items so you can alter the values in your page template?  
In the section this works:

```lia-code-sample
{# Multiple Items in Group #}
{% module_attribute 'group_name' %}
[
{ field_name: 'field value 1' },
{ field_name: 'field value 2' }
]
{% end_module_attribute %}

```

But - how do you modify this to allow your page template to use this or the context you put in the page template. For most items you add context like this:

```lia-code-sample
{% module_attribute 'content' %}
{{ 
context.intro || '<h2>Heading Here</h2>
<p class="uk-text-center@m">This is where your content goes .</p>'
}}
{% end_module_attribute %}

```

How do you do this for an array?

---

<div class="post-metadata">

**Author:** ![josephLayden](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/josephlayden/32/68653_2.png) [@josephLayden](https://community.hubspot.com/u/josephLayden)\
**Post date:** [September 2, 2022, 5:49pm UTC](https://community.hubspot.com/t/passing-section-context-data-to-nested-group-in-custom-module/64305/6 "2022-09-02T17:49:23Z")

</div>

Working snippet w context and image:

```lia-code-sample
{% module_attribute 'card_content' %}
 [{ 
 image_field: {{ context.image || "{'width': 360, 'height': 270, 'src': '../images/placeholders/360x270.png', 'alt': 'card image'}" }}, 
 title: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit sed', 
 description: 'Lorem ipsum dolor, sit amet consectetur adipisicing elit. Perspiciatis a minima facere earum eum eligendi. Facilis laborum vero vitae quaerat.', 
 date: 'May 5 2022', 
 location: 'Chicago, IL', 
 cta_text: 'read more'
 },
 { 
 image_field: {{ context.image || "{'width': 360, 'height': 270, 'src': '../images/placeholders/360x270.png', 'alt': 'card image'}" }}, 
 title: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit sed', 
 description: 'Lorem ipsum dolor, sit amet consectetur adipisicing elit. Perspiciatis a minima facere earum eum eligendi. Facilis laborum vero vitae quaerat.', 
 date: 'May 5 2022', 
 location: 'Chicago, IL', 
 cta_text: 'read more'
 },
 { 
 image_field: {{ context.image || "{'width': 360, 'height': 270, 'src': '../images/placeholders/360x270.png', 'alt': 'card image'}" }}, 
 title: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit sed', 
 description: 'Lorem ipsum dolor, sit amet consectetur adipisicing elit. Perspiciatis a minima facere earum eum eligendi. Facilis laborum vero vitae quaerat.', 
 date: 'May 5 2022', 
 location: 'Chicago, IL', 
 cta_text: 'read more'
 }]
 {% end_module_attribute %}

```

Thank you!
