Setting module default values within templates

hello I am trying to understand how setting default module values with a template for example

How you set can set default values of card module eg

{% module “module_170904438127413” path=“/mytheme2024/modules/card”, label=“card” ,
images=[ {
“src”:“https://5136573.fs1.hubspotusercontent-na1.net/hub/5136573/hubfs/raw_assets/public/mytheme2024/images/team-image.jpg?width=605&height=449&name=team-image.jpg”
},
{
“src”:“https://5136573.fs1.hubspotusercontent-na1.net/hub/5136573/hubfs/raw_assets/public/mytheme2024/images/team-image.jpg?width=605&height=449&name=team-image.jpg”
},
{
“src”:“https://5136573.fs1.hubspotusercontent-na1.net/hub/5136573/hubfs/raw_assets/public/mytheme2024/images/team-image.jpg?width=605&height=449&name=team-image.jpg”
}
]

%}

I can see the fielding names eg item.image.src that appears within a for loop

Is there any hubspot pages that display any examples

Hi @simonp I’m not sure there is a specific resource for your question, here is an example of JSON for a similar module that has a card field with image and rich text:

[
 {
 "children": [
 {
 "default": {
 "loading": "lazy",
 "alt": "11",
 "src": "https://45340635.fs1.hubspotusercontent-na1.net/hubfs/45340635/11.png",
 "width": 1000,
 "height": 1000,
 "max_width": 1000,
 "max_height": 1000
 },
 "display_width": null,
 "id": "card.image",
 "label": "Image",
 "locked": false,
 "name": "image",
 "required": false,
 "resizable": true,
 "responsive": true,
 "show_loading": true,
 "type": "image"
 },
 {
 "default": "<h3>This is a title</h3><p>description text here.</p>",
 "display_width": null,
 "enabled_features": [
 "emoji",
 "lists",
 "font_size",
 "standard_emphasis",
 "block",
 "font_family",
 "alignment",
 "advanced_emphasis"
 ],
 "id": "card.text",
 "label": "Content",
 "locked": false,
 "name": "text",
 "required": false,
 "type": "richtext"
 }
 ],
 "default": [
 {
 "image": {
 "loading": "lazy",
 "alt": "11",
 "src": "https://45340635.fs1.hubspotusercontent-na1.net/hubfs/45340635/11.png",
 "width": 1000,
 "height": 1000,
 "max_width": 1000,
 "max_height": 1000
 },
 "text": "<h3>This is a title</h3><p>description text here.</p>"
 },
 {
 "image": {
 "loading": "lazy",
 "alt": "11",
 "src": "https://45340635.fs1.hubspotusercontent-na1.net/hubfs/45340635/11.png",
 "width": 1000,
 "height": 1000,
 "max_width": 1000,
 "max_height": 1000
 },
 "text": "<h3>This is a title</h3><p>description text here.</p>"
 },
 {
 "image": {
 "loading": "lazy",
 "alt": "11",
 "src": "https://45340635.fs1.hubspotusercontent-na1.net/hubfs/45340635/11.png",
 "width": 1000,
 "height": 1000,
 "max_width": 1000,
 "max_height": 1000
 },
 "text": "<h3>This is a title</h3><p>description text here.</p>"
 }
 ],
 "display_width": null,
 "expanded": false,
 "id": "card",
 "label": "Card",
 "locked": false,
 "name": "card",
 "occurrence": {
 "default": 3,
 "min": 1,
 "sorting_label_field": "card.title"
 },
 "required": false,
 "tab": "CONTENT",
 "type": "group"
 }
]

and the module.html:

{# Image #}

 {% if module.styles.image.corner.radius >= 0 %}
 .card__image {
 border-radius: {{ module.styles.image.corner.radius ~ "px" }};
 }
 {% endif %}

 {# Card #}

 .card {
 {% if module.styles.card.background.background_type == "color" and module.styles.card.background.color.color %}
 background-color: rgba({{ module.styles.card.background.color.color|convert_rgb }}, {{ module.styles.card.background.color.opacity / 100 }});
 {% elif module.styles.card.background.background_type == "gradient" %}
 background: {{ module.styles.card.background.gradient.css }};
 {% elif module.styles.card.background.background_type == "image" %}
 {{ module.styles.card.background.image.css }}
 {% endif %}
 {{ module.styles.card.border.border.css }}
 {% if module.styles.card.corner.radius >= 0 %}
 border-radius: {{ module.styles.card.corner.radius ~ "px" }};
 {% endif %}
 {{ module.styles.card.spacing.spacing.css }}
 }

 {% end_scope_css %}
 </style>
{% end_require_css %}

{# Cards #}

<div class="cards">

 {# Loops through each card in the cards repeater #}

 {% for card in module.card %}
 <section class="cards__card card">
 {% if card.image.src %}
 {% set sizeAttrs = 'width="{{ card.image.width }}" height="{{ card.image.height }}"' %}
 {% if card.image.size_type == "auto" %}
 {% set sizeAttrs = 'style="max-width: 100%; height: auto;"' %}
 {% elif card.image.size_type == "auto_custom_max" %}
 {% set sizeAttrs = 'width="{{ card.image.max_width }}" height="{{ card.image.max_height }}" style="max-width: 100%; max-height: auto;"' %}
 {% endif %}
 {% set loadingAttr = card.image.loading != "disabled" ? 'loading="{{ card.image.loading }}"' : "" %}
 <img class="card__image" src="{{ card.image.src }}" alt="{{ card.image.alt }}" {{ loadingAttr }} {{ sizeAttrs }}>
 {% endif %}
 {% if card.text %}
 <div class="card__text">
 {{ card.text }}
 </div>
 {% endif %}
 </section>
 {% endfor %}

</div>

Hello Many thank for help.

I think I figured how to set this.

Reread thacadamey page regarding sections

When in the page editor and you stick the page into developermode by adding ?developerMode=true

This gives to ablity to copy a section as hubl, by using thios i can see how you overide or adjust the default values of a module when within a template so i can see in respect to card

{% dnd_module
path=“/mytheme2024/modules/card”,
offset=0,
width=12,
card=[ {
“image” : {
“alt” : “Artboard 1”,
“height” : 106,
“loading” : “lazy”,
“max_height” : 106,
“max_width” : 508,
“src” : “https://5136573.fs1.hubspotusercontent-na1.net/hubfs/5196573/Artboard%201.png”,
“width” : 508
},
“text” : “<h3>new 1</h3>\n<p>Contextualcnew1.</p>”
}, {
“image” : {
“alt” : “newlogoTest”,
“height” : 62,
“loading” : “lazy”,
“max_height” : 62,
“max_width” : 300,
“src” : “https://5136573.fs1.hubspotusercontent-na1.net/hubfs/51769173/newlogoTest.svg”,
“width” : 300
},
“text” : “<h3>Text2</h3>\n<p>text 2.</p>”
}, {
“image” : {
“alt” : “newlogoTest”,
“height” : 62,
“loading” : “lazy”,
“max_height” : 62,
“max_width” : 300,
“src” : “https://5136573.fs1.hubspotusercontent-na1.net/hubfs/5453573/newlogoTest.svg”,
“width” : 300
},
“text” : “<h3>text3</h3>\n<p>text3.</p>”
} ]
%}
{% end_dnd_module %}

Hi @simonp yes, this is another way that you can generate the base code that you need for the default values.

One important thing to note about developer mode and copying hubL.

If the module was already on the page in the template, the hubL will only copy values for settings you changed.

If you need all values to copy, you need to manually add the module via drag-and-drop, adjust all of your values, then copy the hubL.

Best of luck with your module!