CMS Development

scottrief
Member

Custom Module - Export to Template

SOLVE

Is there a way to export a custom module's output to a variable for use later on in the template? 

 

Use Case

I have a custom module that allow's non-technical email authors to select an icon from a drop down and type in accompanying text for inclusion into the email body. Right now, I have three modules to build the email body:

 

  1. Email Content body 1
  2. Icon list (custom module)
  3. Email Content body 2

This allows an email author to type introductory text, create a custom icon/description list and follow up with closing text. (see screenshot below).

 

What I'd like to do is have one email content body module and the icon list (custom module).  Then use the HubL Replace filter to find/replace a token in the email body with the icon list from the custom module. e.g. replace( "{icon list here}", icon_list_output ).

 

Is it possible to do this by exporting a custom module's output to a variable so I can include it in the email body using the replace filter? 

 

sample_email_body.png

0 Upvotes
1 Accepted solution
Jsum
Solution
Key Advisor

Custom Module - Export to Template

SOLVE

@scottrief,

 

You can export any module to to the template. What this does is make it's data available through the use of data tokens, so for instance:

{% text 'random_text' label="Input Random Text", value="blah blah blah", export_to_template_context=True %}

would allow you to access the value of the module by:

{{ widget_data.random_text.value }}

So the value of that module would be output anywhere that this token is placed in a template. 

 

This might be a but different for custom modules. At least you will see a few more steps in your name tree for the data token:

{{ widget_data.custom_module.module_type.html }}

That is just an example. You can find the actual steps by going to your email in a browser preview, clicking the hubspot sprocket in the top right and vew the developer info. use ctrl+f to search for the module in the data and it will show you the "tiers" of the json model from the module name down to the value you want form it. If you are familiar at al with json then you shouldn't have any issue. 

View solution in original post

5 Replies 5
Jsum
Solution
Key Advisor

Custom Module - Export to Template

SOLVE

@scottrief,

 

You can export any module to to the template. What this does is make it's data available through the use of data tokens, so for instance:

{% text 'random_text' label="Input Random Text", value="blah blah blah", export_to_template_context=True %}

would allow you to access the value of the module by:

{{ widget_data.random_text.value }}

So the value of that module would be output anywhere that this token is placed in a template. 

 

This might be a but different for custom modules. At least you will see a few more steps in your name tree for the data token:

{{ widget_data.custom_module.module_type.html }}

That is just an example. You can find the actual steps by going to your email in a browser preview, clicking the hubspot sprocket in the top right and vew the developer info. use ctrl+f to search for the module in the data and it will show you the "tiers" of the json model from the module name down to the value you want form it. If you are familiar at al with json then you shouldn't have any issue. 

ikonic_media
Participant

Custom Module - Export to Template

SOLVE

Has this process changed? This code worked for me in the past but no longer pulls the custom field into my blog post template. 

 

I created a new blog template with the new design manager and none of my custom fields appear. The fields used to appear in the modules list in the right sidebar.

0 Upvotes
Jsum
Key Advisor

Custom Module - Export to Template

SOLVE

@ikonic_media,

 

This should still work exactly the same. I'm not sure why the new design manager would break your fields. Have you tried calling support?

0 Upvotes
jestlinbaum
Participant

Custom Module - Export to Template

SOLVE

I am also unable to get any custom modules to show on my post template using the new design manager. I have a support ticket in. I will post if a solution is found.

0 Upvotes
ndwilliams3
Key Advisor

Custom Module - Export to Template

SOLVE

I'm starting to use the new design manager as I was told that V2 will rollout permanently later this month. I have several modules that do exactly the same thing create variables that are used later in the page. They also pull in global modules as well based on a choice selection. Can't seem to get the same thing working in V2! 

0 Upvotes