# Calling a module from within a module

**URL:** <https://community.hubspot.com/t/calling-a-module-from-within-a-module/20210>\
**Category:** CMS Development\
**Created:** [April 20, 2020, 11:28am UTC](https://community.hubspot.com/t/calling-a-module-from-within-a-module/20210 "2020-04-20T11:28:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oloph](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/oloph/32/44643_2.png) [@Oloph](https://community.hubspot.com/u/Oloph)\
**Post date:** [April 20, 2020, 11:28am UTC](https://community.hubspot.com/t/calling-a-module-from-within-a-module/20210/1 "2020-04-20T11:28:33Z")

</div>

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!

```auto
<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" %}

```

---

<div class="post-metadata">

**Author:** ![BenSBM](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/bensbm/32/75413_2.png) [@BenSBM](https://community.hubspot.com/u/BenSBM)\
**Post date:** [April 20, 2020, 12:08pm UTC](https://community.hubspot.com/t/calling-a-module-from-within-a-module/20210/2 "2020-04-20T12:08:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Oloph](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/oloph/32/44643_2.png) [@Oloph](https://community.hubspot.com/u/Oloph)\
**Post date:** [April 20, 2020, 7:22pm UTC](https://community.hubspot.com/t/calling-a-module-from-within-a-module/20210/3 "2020-04-20T19:22:18Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![JRodriguez76](https://avatars.discourse-cdn.com/v4/letter/j/e5b9ba/32.png) [@JRodriguez76](https://community.hubspot.com/u/JRodriguez76)\
**Post date:** [January 17, 2025, 12:56am UTC](https://community.hubspot.com/t/calling-a-module-from-within-a-module/20210/4 "2025-01-17T00:56:59Z")

</div>

Hi, Can we implement a module within a module?  
I have to repeat my code?

---

<div class="post-metadata">

**Author:** ![CXurious](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cxurious/32/71570_2.png) [@CXurious](https://community.hubspot.com/u/CXurious)\
**Post date:** [March 28, 2025, 4:04pm UTC](https://community.hubspot.com/t/calling-a-module-from-within-a-module/20210/5 "2025-03-28T16:04:34Z")

</div>

The way Hubspot solves for this is interesting. This is where Macros come in. You can create your “atoms” as macros then call them in other components to achieve what, in some CMSs are known as “complex components”--or combining multiple components to achieve a single experience.

There is no way to call a module within a module in hubspot. So you have to create the element you want to repurpose as a macro.  
Just remember that your component field JSON has to match to get a consistent authoring/display experience.

I’m pretty sure it was [this dhug video](https://www.youtube.com/watch?v=GRXDz9nY5yM&list=PLTGNq2fWP3b38i_YC6LNiEgrt7pMLqt2w&index=13) that helped me understand the macro as the solution to the complex component.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![fdido](https://avatars.discourse-cdn.com/v4/letter/f/ba9def/32.png) [@fdido](https://community.hubspot.com/u/fdido)\
**Post date:** [December 1, 2022, 10:39am UTC](https://community.hubspot.com/t/calling-a-module-from-within-a-module/20210/6 "2022-12-01T10:39:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CXurious](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/cxurious/32/71570_2.png) [@CXurious](https://community.hubspot.com/u/CXurious)\
**Post date:** [July 17, 2024, 2:46pm UTC](https://community.hubspot.com/t/calling-a-module-from-within-a-module/20210/7 "2024-07-17T14:46:15Z")

</div>

[Adding this more recent thread as a referernce.](https://community.hubspot.com/t5/CMS-Development/Module-within-a-Module/td-p/768057)
