CMS Development

Oloph
Participant

Calling a module from within a module

SOLVE

Hi Forum, my apologies if this is already covered, please point me to the resource in that case!

 

I'm wondering if it's possible to "nest" code modules, i.e. calling in the entire functionality from a module in another module. 

In this case I have a 2-column layout thing with left and right containers, which can hold rich text, image, video embed or a blog list. The content editor selects the type of content from a switch in the module. 

So Hubspot has this ready-made video-embed module that pulls in Youtube or Vimeo clips. Can I somehow reference that whole module from my module and get it to work? Or do I need to copy the entire video module code into my module? Seems like bad practice to duplicate code like this. 

I was hoping for something as simple as in the below, like "if 'video' is selected, enable this video module". 

I'm just a designer and self-taught coder.

Thanks!

 

<div class="page-center content-section">
  <div class="two-column-highlight">
    
    <!-- RICH TEXT BOX -->
    <div class="highlight text {% if module.image_position =='img_left' %}image-left{% endif %}">
      {% inline_rich_text field="highlight_text" value="{{ module.highlight_text }}" %}
    </div>
    
    <!-- OPTION: IMAGE -->
    {% if module.media_content == 'image' %}
    <div class="highlight {% if module.image_position =='img_left' %}image-left{% endif %}">
        <img src="{{ module.image.src }}" alt="{{ module.image.alt }}" {{ sizeAttrs }}>
    </div>
    
    <!-- OPTION: VIDEO -->
    {% elif module.media_content == 'video' %}
    <div class="highlight {% if module.image_position =='img_left' %}image-left{% endif %}">
      {% module "module_1587375821196241" path="@hubspot/video_embed_lp", label="Video Embed - LP" %}
0 Upvotes
1 Accepted solution
BenSBM
Solution
Contributor | Elite Partner
Contributor | Elite Partner

Calling a module from within a module

SOLVE

Hi Oloph,

 

In both the design manager and local dev with the CLI, you will get an error showing that "'module' is disabled in this context" - so unfortunately I don't think that this is possible to do and you would need to add the code directly to your module.

View solution in original post

3 Replies 3
BenSBM
Solution
Contributor | Elite Partner
Contributor | Elite Partner

Calling a module from within a module

SOLVE

Hi Oloph,

 

In both the design manager and local dev with the CLI, you will get an error showing that "'module' is disabled in this context" - so unfortunately I don't think that this is possible to do and you would need to add the code directly to your module.

fdido
Member

Calling a module from within a module

SOLVE

hmm then it would be sound dumb to use hubspot than just react huh

0 Upvotes
Oloph
Participant

Calling a module from within a module

SOLVE

Many thanks for replying Ben. So we're not quite there where we can build portable minimodules for re-use in other modules. 

OK, will research workarounds. And learn!

 

Best!

0 Upvotes