CMS Development

alvarofranz
Contributor

Use a variable as a module param value

SOLVE

I am trying to pass this information to a custom module:

 

 

 

{% set parent_items = [
{
"parent_item_link": {
"url": {
"href": "https://example.com"
},
"open_in_new_tab": true,
"rel": null
},
"parent_item_label": "Example 1"
},
{
"parent_item_link": {
"url": {
"href": "https://example.net"
},
"open_in_new_tab": false,
"rel": null
},
"parent_item_label": "Example 2"
},
{
"parent_item_link": {
"url": {
"href": "https://example.org"
},
"open_in_new_tab": true,
"rel": null
},
"parent_item_label": "Example 3"
}
] %}

{% module "hero_banner"
path='../modules/breadcrumb-hero',
label='Breadcrumb Hero',
parent_items=parent_items,
current_item_label='Current Page',
offset=0
%}

 

 

 

This doesn't work, but if I provide the value directly without setting it to a variable first, it works perfectly:

 

 

 

{% module "hero_banner"
path='../modules/breadcrumb-hero',
label='Breadcrumb Hero',
parent_items=[
  {
  "parent_item_link": {
  "url": {
  "href": "https://example.com"
  },
  "open_in_new_tab": true,
  "rel": null
  },
  "parent_item_label": "Example 1"
  },
  {
  "parent_item_link": {
  "url": {
  "href": "https://example.net"
  },
  "open_in_new_tab": false,
  "rel": null
  },
  "parent_item_label": "Example 2"
  },
  {
  "parent_item_link": {
  "url": {
  "href": "https://example.org"
  },
  "open_in_new_tab": true,
  "rel": null
  },
  "parent_item_label": "Example 3"
  }
  ],
current_item_label='Current Page',
offset=0
%}

 

 

 

How can I pass the value as a variable instead?

0 Upvotes
1 Accepted solution
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Use a variable as a module param value

SOLVE

Hi @alvarofranz,

 

Could you try this:

{% module "hero_banner"
path='../modules/breadcrumb-hero',
label='Breadcrumb Hero',
parent_items="{{parent_items}}",
current_item_label='Current Page',
offset=0
%}


Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


View solution in original post

6 Replies 6
Teun
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Use a variable as a module param value

SOLVE

Hi @alvarofranz,

 

Could you try this:

{% module "hero_banner"
path='../modules/breadcrumb-hero',
label='Breadcrumb Hero',
parent_items="{{parent_items}}",
current_item_label='Current Page',
offset=0
%}


Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


alvarofranz
Contributor

Use a variable as a module param value

SOLVE

Thanks, this works as expected. I wonder why this is the way to do it, I thought {{ }} is used to print data, not to pass it as a param.

Teun
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Use a variable as a module param value

SOLVE

Great question, not one I can answer tho. I tried to pass variables in different ways, and this one worked, so I went with it 😅



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


alvarofranz
Contributor

Use a variable as a module param value

SOLVE

Note for future readers, it seems that the quotes are not necessary.

 

All of this works equally fine:

 

{% module "whatever"
path='../modules/whatever',
give_me_some_value={{give_me_some_value}}
%}

{% module "whatever"
path='../modules/whatever',
give_me_some_value='{{give_me_some_value}}'
%}

{% module "whatever"
path='../modules/whatever',
give_me_some_value="{{give_me_some_value}}"
%}
himanshurauthan
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Use a variable as a module param value

SOLVE

Hello @alvarofranz 

use the as keyword to assign the value to a variable and then pass that variable as a parameter.

{% set parent_items = [
    {
        "parent_item_link": {
            "url": {
                "href": "https://example.com"
            },
            "open_in_new_tab": true,
            "rel": null
        },
        "parent_item_label": "Example 1"
    },
    {
        "parent_item_link": {
            "url": {
                "href": "https://example.net"
            },
            "open_in_new_tab": false,
            "rel": null
        },
        "parent_item_label": "Example 2"
    },
    {
        "parent_item_link": {
            "url": {
                "href": "https://example.org"
            },
            "open_in_new_tab": true,
            "rel": null
        },
        "parent_item_label": "Example 3"
    }
] %}

{% module "hero_banner"
    path='../modules/breadcrumb-hero',
    label='Breadcrumb Hero',
    parent_items=parent_items as parent_items_variable,  # Assign the variable
    current_item_label='Current Page',
    offset=0
%}


as parent_items_variable, you assign the value of parent_items to the variable parent_items_variable.  pass parent_items_variable as the parent_items parameter to the module.

Digital Marketing & Inbound Expert In Growth Hacking Technology
0 Upvotes
alvarofranz
Contributor

Use a variable as a module param value

SOLVE

Thanks, but this doesn't work... now nothing shows at all. I'm also not really understanding what this is supposed to do.

0 Upvotes