CMS Development

JR6
Participant

DisabledException: 'module' is disabled in this context

Hi Devs,


The Problem:

I recently run into an issue saving custom modules in my hubspot blog-index dnd template.
The error notice told me:

Error while updating a module
Please click "Apply changes", try again, or check if the "blog-listings" module has errors. (translated)

After further investigation the chrome dev-tools notified me about the problem, mentioned in this subject:

DisabledException : 'module' is disabled in this context

Further investigation:
I checked all my templates for nested modules and destructed my whole theme in another developer account.


Removing and reinserting modules showed me, that my post-listing modules caused this issue. More precisely, my readingtime estimation macro seems to cause the error.

With the message 'module' is disabled in this context in mind, maybe some blog-posts contain modules or further logic in their content. It wasn't an option to edit all my blog-post contents.
Debugging their post_body didn't show any modules neither.

My thoughts to fix it
I guess my readingtime macro causes hubspot to parse the post_body of my posts in my custom module context

<!-- old and problem causing example -->
{% macro readingtime(mytext) %}
	{% set time = mytext|striptags|wordcount|divide(225)|round(0, "ceil") %}
	{{ time > 0 ? time : 1 }}
{% endmacro %}

<!-- fixed version of readingtime estimation escaping curly braces -->
{% macro readingtime(mytext) %}
	{% set time = mytext|escape_jinjava|striptags|wordcount|divide(225)|round(0, "ceil") %}
	{{ time > 0 ? time : 1 }}
{% endmacro %}

<!-- macro call in a loop in a custom module -->
{{ readingtime(content.post_body) }}

 
To resolve this behaviour i came along to the escape_jinjava filter.
It seems, that the problem doesn't occure anymore because of escaping those braces used in hubl templates.

Did someone experienced the same problem or has a reference where this problem is described in detail? I couldn't find a documentation or community post about this topic.
Greetings 🙂

2 Replies 2
Anton
Thought Leader

DisabledException: 'module' is disabled in this context

Hi @JR6

try this reading time script

{% set initialPostWords = content.post_body|striptags|wordcount %}
         {% set calculatedPostWords = (initialPostWords/100) * 100 %}
         {% set finishedPostWords = calculatedPostWords|divide(300)|round(2) %}


{{ finishedPostWords|round }}

using it for years and never had issues with it. 

 

best, 

Anton

Anton Bujanowski Signature
0 Upvotes
JR6
Participant

DisabledException: 'module' is disabled in this context

I also found this snippet while debugging, but it didn't solve the issue.

0 Upvotes