CMS Development

adrien-gueret
Member

Custom modules and default values

SOLVE

Hi there,

I'm building a template for a landing page and have create some custom modules.

On the editor, the creator can enable or not a module:

 

Capture d’écran 2020-06-09 à 13.09.39.png

If the module is enable, it'll be rendered in the landing page.

As you can see in the screen above, it's checked by default, and the module is indeed rendered on the page when we just create it.

 

But if my Hubl template tries to get the enable value, null is received, not true:

{%
        module "myModule"
        path="../path/to/module",
        label="My module"
%}

{{ content.widgets.myModule.body.enable }} // null

If the page creator toggles the enable switch, then the value is now updated correctly and the correct boolean is printed. Otherwise, null is received.

 

That's said, I've understood that my template can override the default values set by the custom module, like below:

{%
        module "myModule"
        path="../path/to/module",
        label="My module",
        enable=true
%}

{{ content.widgets.myModule.body.enable }} // true!

When doing that, the default value is correctly gotten. Well, almost...

When creating a new page from the template, it seems that it works randomly. Sometimes it does and everything is OK, and sometimes it does not, and the creator has to reload the page to make it work. What do I do wrong?

 

Anyway, even when it works, it's required to define this default value on the custom module and when calling it on the Hubl template, which is not so convenient...

 

So, this is the context, now my questions:

 

  1. Can you confirm that the correct way for a template to get actual module values is to set the default ones when calling it?
  2. If so, why does it work only sometimes?
  3. And what's the point of defining default values directly on module fields (like my first screenshot) if we have to redefine them in the templates? It's very confusing to not get them from the template.

Thanks in advance 🙂

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

Custom modules and default values

SOLVE
Hi Adrien,
You're writing with Boolean "widgets". The don't have a specific value. Only "true" or "false". Therefore you have to write

{% if.module.widget_name %}
some content that should be visible if the checkbox is checked(true state)

{% endif %}

To make your life easier copy the snippet of the widget and paste your content between the if statement.

For your questions:

1. It's not nessesary too define default values in modules. But it can be a Time saver.

2. If you're calling/using the same module more than once in a template you have to give each an individual name and label. Otherwise they will override each other.

3. Imo default values in modules make sense of you're using the same module multiple times with the same content or want to show the content editor "what is where".
On normal occasion you define the content of the module in the "page building mode"
Anton Bujanowski Signature

View solution in original post

2 Replies 2
Anton
Solution
Recognized Expert | Diamond Partner
Recognized Expert | Diamond Partner

Custom modules and default values

SOLVE
Hi Adrien,
You're writing with Boolean "widgets". The don't have a specific value. Only "true" or "false". Therefore you have to write

{% if.module.widget_name %}
some content that should be visible if the checkbox is checked(true state)

{% endif %}

To make your life easier copy the snippet of the widget and paste your content between the if statement.

For your questions:

1. It's not nessesary too define default values in modules. But it can be a Time saver.

2. If you're calling/using the same module more than once in a template you have to give each an individual name and label. Otherwise they will override each other.

3. Imo default values in modules make sense of you're using the same module multiple times with the same content or want to show the content editor "what is where".
On normal occasion you define the content of the module in the "page building mode"
Anton Bujanowski Signature
sharonlicari
Community Manager
Community Manager

Custom modules and default values

SOLVE

Hey @adrien-gueret 

 

Thank you for the information provided.I'll tag a few experts that can share their experience with you.  

 

Hey @Stephanie-OG @Anton @albertsg  any thoughts you would like to share with @adrien-gueret ?   

 

Thanks

Sharon


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !




0 Upvotes