let’s say I have my_var set to equal “kittens!” in my_module.
In the template,
{{ content.widgets.my_module.body.my_var }}
Always returns 0, and I can’t figure out where I’ve gone wrong in life.
let’s say I have my_var set to equal “kittens!” in my_module.
In the template,
{{ content.widgets.my_module.body.my_var }}
Always returns 0, and I can’t figure out where I’ve gone wrong in life.
Hi @tony5280
If your custom module has this:
{% set my_var = "kittens" %}
I doubt you can export this directly from a module.
What you can do is create a text field, set a default value and export that value.
For example, let’s say your module is called “my-kittens-module” and has a text field with the id of “my_text_field” - you would first add the module to your template like this (not through the page editor):
{% module "module_11111111111111" path="/theme/custom-modules/my-kittens-module", label="My Kittens Module" %}
Then to get the variable, you would add:
{{ content.widgets.module_11111111111111.body.my_text_field }}
Note that the “module_11111111111111” will be an autogenerated value when you copy the module snippet and it changes everytime you copy it in the desing manager.
Thanks!
So is there no way to do with with a module that already exists in a page? My experience with templates in this system is that they are less like I would expect, and more like cookie cutters - stamping out a cookie, then changing the template doesn’t affect the cookies I’ve already stamped out.
And in this case, my pages are already built.
From a base template, is there a way to detect if a particular module is loaded?
Sure thing!
I am not aware of any HubL functions that would allow detecting whether a module is present on a page. It also may be per design, as the same module in design manager technically would be two different modules (or more precisely, instances of a module) if placed on the same page twice.
Ultimately depends on what you are trying to build but utilizing javascript within modules to set variables might also be an option.
@tony5280 - are you looking for the “export to template context” functionality? I use this broadly to create customized blog environments etc.
In the preamble to a template declare a way to set a value value such as:
{% module “alt_language” path=“../modules/Lang-Choice” label=‘Choose the second language’, lang_choice=‘None’, export_to_template_context=true %}
In this case I use a module to define a drop down choice.
You set the value for each instance of thhe use of this template via the page editor.
The value is accessed using (in this case) the rather odd reference:
widget_data.alt_language.body.lang_choice
Best of luck!
Steve