CMS Development

BGrennan
Contributor

Control default number of objects in module when included in template

I've a module that I'm using twice in one template.

 

In the first instance I'm using the repeater fields default number of objects (3)

 

In the second instance I wantto override it so that it only shows one object by default there.

 

So I'm looking for somethnig like

 {% dnd_module "zig-zag-posts" path="/theme/modules/zig-zag", label="zig-zag posts" default_objects=10 %}
      {% end_dnd_module %}
0 Upvotes
3 Replies 3
miljkovicmisa
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

Control default number of objects in module when included in template

Hello @BGrennan ! Thank you for posting in the forum,
As far as I am concerned this is not possible as the default number of objects is defined in the module itself so any instance of that module will carry that information throughout its lifespan.
One thing you could possibly do is make some template-level defaults, if you show us what does the module look like I could help you with the hubl code, but basically its between these lines:

 

{# This is how it would look if you had a group with repeatable items #}
{% dnd_module 
  "zig-zag-posts" 
  path="/theme/modules/zig-zag", 
  label="zig-zag posts",
  your_objects_name = [
    {"object_field": "some value"},
    {"object_field": "another value"},
    {"object_field": "one more value"}
  ]
%}
{% end_dnd_module %}

{# and thats whith just a repeatable item #}
{% dnd_module 
  "zig-zag-posts" 
  path="/theme/modules/zig-zag", 
  label="zig-zag posts",
  your_objects_name = [
    "some value",
    "another value",
    "one more value"
  ]
%}
{% end_dnd_module %}

 

 

So you may have defined a default of 5 objects but with this code your template will show the three you have defined here. This is called template-level default value and it overrides the default value you put in your module.
More info on using modules in templates here,

Template level default values info here.

Hope you found my answer useful, if so mark it as a solution.

P.S. Thank you for the mention @dennisedson !

BGrennan
Contributor

Control default number of objects in module when included in template

Thanks @miljkovicmisa

 

I got a similar solution from @Stephanie-OG

 

 {% dnd_module "zig-zag" path="/theme/modules/zig-zag", label="zig-zag" reverse_pattern="true" %}
  {% module_attribute "field_group"  is_json=True %}
  [
            {
                "title": "Insert Title",
                "body_text": "<p><span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In consequat, arcu id sollicitudin vehicula, orci erat blandit velit, ac iaculis leo nibh eu purus. Duis id sagittis dolor. Suspendisse sed ullamcorper lorem, quis hendrerit sem.</span></p>",
                "cta_button": "00000-00000-000000",
                "image_field": { "src": "imagesource.com/img.jpg", "alt": "Alt Title", "width": 1373, "height": 713, "max_width": 1373, "max_height": 713 },
               
            }
        ]
  {% end_module_attribute %}
      {% end_dnd_module %}

 

dennisedson
HubSpot Product Team
HubSpot Product Team

Control default number of objects in module when included in template

@miljkovicmisa 👋

Any thoughts on how to solve this? 

0 Upvotes