<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: HubSpot Custom Module Starter Code Snippet in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1129731#M42569</link>
    <description>&lt;P&gt;This is really cool, thank you for sharing it with the Community!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":clapping_hands:"&gt;👏&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 31 Mar 2025 13:33:08 GMT</pubDate>
    <dc:creator>albertsg</dc:creator>
    <dc:date>2025-03-31T13:33:08Z</dc:date>
    <item>
      <title>HubSpot Custom Module Starter Code Snippet</title>
      <link>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1129251#M42560</link>
      <description>&lt;P&gt;When I create custom modules, I often need similar code, and I found myself writing the same stuff over and over. So I created a little snippet I use to start a new module. I just copy and paste it into the HTML section of a custom module and make adjustments as needed.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I thought I would share it here as it might help other developers save some time. You can also find this on my &lt;A href="https://bootstrapcreative.com/resources/hubspot-hubl-docs-cheat-sheet/" target="_blank" rel="noopener"&gt;HubSpot developer cheat sheet&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;  {#
    HubSpot uses different prefixes so this just gets the number    
    module_#########
    widget_#########
    outputs just the number
    #}
    {% set instanceID = name[7:] %}
    {{ instanceID }}
    
    &amp;lt;div class="module-class" id="module{{instanceID}}"&amp;gt;
        &amp;lt;div class="row-fluid"&amp;gt;
            &amp;lt;div class="span6"&amp;gt;A&amp;lt;/div&amp;gt;  
            &amp;lt;div class="span6"&amp;gt;B&amp;lt;/div&amp;gt; 
        &amp;lt;/div&amp;gt;  
    &amp;lt;/div&amp;gt;
    
    {% require_head %}
    {# optional - if you need to add something to the HEAD #}
    {% end_require_head %}
    
    {% require_css %}
    &amp;lt;style&amp;gt;
    {% scope_css %}
    {% end_scope_css %}
    
    &amp;lt;/style&amp;gt;
    {% end_require_css %}
    
    
    {% require_js %}
    &amp;lt;script&amp;gt;
    document.addEventListener("DOMContentLoaded", function () {
        const moduleWrapper = document.querySelector("#module{{ instanceID }}");
    });
    
    window.addEventListener("load", (event) =&amp;gt; {
    
    });
    &amp;lt;/script&amp;gt;
    {% end_require_js %}
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Mar 2025 10:37:14 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1129251#M42560</guid>
      <dc:creator>Jake_Lett</dc:creator>
      <dc:date>2025-03-29T10:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: HubSpot Custom Module Starter Code Snippet</title>
      <link>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1129599#M42563</link>
      <description>&lt;P&gt;Hi &lt;SPAN style="background: var(--ck-color-mention-background); color: var(--ck-color-mention-text);"&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/72866"&gt;@Jake_Lett&lt;/a&gt;&lt;/SPAN&gt;, I hope that you are well!&lt;BR /&gt;&lt;BR /&gt;This is great, thanks so much for sharing this Custom Module Snippet that you created with the HubSpot Community!&lt;BR /&gt;&lt;BR /&gt;This will be helpful for many Community Members, I am sure! &lt;span class="lia-unicode-emoji" title=":red_heart:"&gt;❤️&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Have a lovely day!&lt;BR /&gt;&lt;BR /&gt;Warmly,&lt;BR /&gt;Bérangère&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 08:00:06 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1129599#M42563</guid>
      <dc:creator>BérangèreL</dc:creator>
      <dc:date>2025-03-31T08:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: HubSpot Custom Module Starter Code Snippet</title>
      <link>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1129625#M42564</link>
      <description>&lt;P&gt;This is gold&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/72866"&gt;@Jake_Lett&lt;/a&gt;&amp;nbsp;! Thanks for sharing!&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 08:58:55 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1129625#M42564</guid>
      <dc:creator>Anton</dc:creator>
      <dc:date>2025-03-31T08:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: HubSpot Custom Module Starter Code Snippet</title>
      <link>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1129731#M42569</link>
      <description>&lt;P&gt;This is really cool, thank you for sharing it with the Community!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":clapping_hands:"&gt;👏&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 13:33:08 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1129731#M42569</guid>
      <dc:creator>albertsg</dc:creator>
      <dc:date>2025-03-31T13:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: HubSpot Custom Module Starter Code Snippet</title>
      <link>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1129810#M42572</link>
      <description>&lt;P&gt;Nice one&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/72866"&gt;@Jake_Lett&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;</description>
      <pubDate>Mon, 31 Mar 2025 16:30:31 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1129810#M42572</guid>
      <dc:creator>evaldas</dc:creator>
      <dc:date>2025-03-31T16:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: HubSpot Custom Module Starter Code Snippet</title>
      <link>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1133544#M42655</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/72866"&gt;@Jake_Lett&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nice default. I have a few options that I use on my projects for different aspects.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Unique ID&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If you only want a ID instead of module_ of widget_ you could also use &lt;CODE&gt;{% name|md5 %}&lt;/CODE&gt; This will result in a value with only numbers. This will create a unique ID for the module.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Fixing scope_css or alternative&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In your snippet, I see your using &lt;CODE&gt;{% scope_css %}&lt;/CODE&gt;. This can be very usefull, but be aware that this only can be applied when you don't include &lt;CODE&gt;no_wrapper=true&lt;/CODE&gt; to a embedded module. I use the&amp;nbsp;&lt;CODE&gt;no_wrapper=true&lt;/CODE&gt;&amp;nbsp;a lot to minimize the html output of a page. An alternative for that is using css variable and set those options to the main element. In your default css you can setup default and overwrite it inside the inline styles for each module. This way you will minimize your css.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HTML&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;div class="module" style="--text-color: #fff; --bg-color: #000;"&amp;gt;
  module
&amp;lt;/div&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CSS&lt;/P&gt;
&lt;LI-CODE lang="css"&gt;.module{
  color: var(--text-color, #fff);
  background-color: var(--bg-color, #000);
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Optimizing javascript&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;When I'm looking at the javascript, I use the module.js. If you use the module multiple times on your page you can optimize your code by making a loop out of your function.&amp;nbsp;This way you will minimize your JS. This will also work if you are using repeaters inside a module.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;document.addEventListener('DOMContentLoaded', function () {
    const modules = document.querySelectorAll('.module-name');
});

modules.forEach(function(modules, index){
  const button = module.querySelector('.button');
  if(button){
    button.addEventListener('click',function(e){
      e.preventDefault();
      console.log('clicked');
    });
  }
});&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hopefully, this gives you a different perspective and some ideas on how it could be set up as well. Let me know what you think of it!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 14:22:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1133544#M42655</guid>
      <dc:creator>Indra</dc:creator>
      <dc:date>2025-04-08T14:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: HubSpot Custom Module Starter Code Snippet</title>
      <link>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1133550#M42657</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/78983"&gt;@Indra&lt;/a&gt;&amp;nbsp;Great suggestions and techniques. Thank you for sharing.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Apr 2025 14:32:59 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/HubSpot-Custom-Module-Starter-Code-Snippet/m-p/1133550#M42657</guid>
      <dc:creator>Jake_Lett</dc:creator>
      <dc:date>2025-04-08T14:32:59Z</dc:date>
    </item>
  </channel>
</rss>

