CMS Development

KSchuller
Participant | Elite Partner
Participant | Elite Partner

"include" is disabled in this context

SOLVE

Trying to create a module and include a snippet (partial) into the module to keep the code segmented and easily manageable -- it throws the error stated in the subject "include" is disabled in this context but it still seems to work just fine.

Is this something to be concerned about? As in will the be deprecated in future updates? Or something similar -- just curious if I should avoid this method even though it seems to currently work

0 Upvotes
1 Accepted solution
matt_scott
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

"include" is disabled in this context

SOLVE

Hey I'm not sure why it's disabled but I know for macro's hubspot recommends doing an import instead, I don't know if it works for html too, maybe if you just call the as variable after the import?
https://developers.hubspot.com/docs/cms/hubl/variables-macros-syntax#import

Matthew Scott
Head of Development | Hubspot Solutions Architect

B2B marketing agency: Specialist B2B content marketing and demand generation for SaaS vendors and HubSpot Users | Deeply Digital | HubSpot Partner since 2010


01926 334003

deeplydigital.co.uk

3 Morton Street, Leamington Spa, CV32 5SY, UK

View solution in original post

6 Replies 6
matt_scott
Solution
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

"include" is disabled in this context

SOLVE

Hey I'm not sure why it's disabled but I know for macro's hubspot recommends doing an import instead, I don't know if it works for html too, maybe if you just call the as variable after the import?
https://developers.hubspot.com/docs/cms/hubl/variables-macros-syntax#import

Matthew Scott
Head of Development | Hubspot Solutions Architect

B2B marketing agency: Specialist B2B content marketing and demand generation for SaaS vendors and HubSpot Users | Deeply Digital | HubSpot Partner since 2010


01926 334003

deeplydigital.co.uk

3 Morton Street, Leamington Spa, CV32 5SY, UK
KSchuller
Participant | Elite Partner
Participant | Elite Partner

"include" is disabled in this context

SOLVE

Thank you @matt_scott this helped a lot!

I now have a global __macro.html file with a bunch of snippets in it, and I can use it like:

 

 

{% from "/MASTER/layouts/__macro.html" import __background %}
{{ __background() }}

 

 

Which doesn't throw the error!

Also neater having a single file which I can pick and choose snippets from!

 

Thank you again!

0 Upvotes
08399
Member

"include" is disabled in this context

SOLVE

I was going through the same issue and have followed this structure and it worked a treat. Thank you both!

0 Upvotes
matt_scott
Top Contributor | Platinum Partner
Top Contributor | Platinum Partner

"include" is disabled in this context

SOLVE

I didn't actually read as far as the from function that's pretty cool, thanks for pointing that one out!
I actually had my individual macros spread out and then imported into my macros.html something like this:

{% import "./components/_cta.html" as _cta %}
	{% set cta = _cta.cta %}
{% import "./components/_form.html" as _form %}
	{% set form = _form.form %}
{% import "./components/_image.html" as _image %}
	{% set image = _image.image %}
{% import "./components/_intro.html" as _intro %}
	{% set intro = _intro.intro %}

but now I can update it to use the from function so I don't have to do the additional sets

Matthew Scott
Head of Development | Hubspot Solutions Architect

B2B marketing agency: Specialist B2B content marketing and demand generation for SaaS vendors and HubSpot Users | Deeply Digital | HubSpot Partner since 2010


01926 334003

deeplydigital.co.uk

3 Morton Street, Leamington Spa, CV32 5SY, UK
Jaycee_Lewis
Community Manager
Community Manager

"include" is disabled in this context

SOLVE

Hi, @KSchuller 👋 Can you provide any additional details to help the community? A code snippet of what you've already tried along with screenshots will help give more context to potential root causes. 

 

To your second question, I do not have any documentation internally or via the public developer docs indicating depreciation of this functionality (partials) 

 

Thank you! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
KSchuller
Participant | Elite Partner
Participant | Elite Partner

"include" is disabled in this context

SOLVE

Thank you, @Jaycee_Lewis , for getting back to me!

 

So in a custom module that I'm making I've got a partial HTML file that I include in the module, like so 

 

 

{% include '../templates/partials/vidyard-new.html' %}

 

 

 

And this will throw the following message in the error console

Warning: "include" is disabled in this context

 

However the include does work despite this message. Which is why I just wanted to confirm it will continue to work -- I can of course include the code directly in the module but the module itself is already 1200+ lines of code so I'm looking to use snippets to make it all easier to manage

 

All the best,

Kyle

0 Upvotes