Hi there,
Is there anyway to remove/change the html span that the widget container uses to wrap the contents?
I am trying to get my code w3c compliant and the span is creating issues.
Thanks in advance for any help
Hi there,
Is there anyway to remove/change the html span that the widget container uses to wrap the contents?
I am trying to get my code w3c compliant and the span is creating issues.
Thanks in advance for any help
Hi @Julian1936,
there is currently only the option to add no_wrapper parameter
no_wrapper=True
to the modules in your template.
Here’s an example:
default rich-text module snippet:
{% module "rich_text" path="@hubspot/rich_text" %}
modified with no_wrapper:
{% module "rich_text" path="@hubspot/rich_text", no_wrapper=True %}
But this will only affect modules that are build into the template by default. If you drag&drop modules on “page-level” into your page they will have the wrapping span/divs.
If you don’t need/want to use the drag&drop areas/functionality you can write your w3c compliant template without them and just implement the HubSpot modules into your layout.
Here’s a very basic example.
<div class="container">
<div class="row">
<div class="span12">
{% module "rich_text" path="@hubspot/rich_text", no_wrapper=True, label="Headline" %}
</div>
</div>
</div>
Writing it without drag&drop could have some big benefits if you’re after a more “corporate” and “easy to use” approach. On the other hand - your marketers/page creators will be won’t be able to change the layout of the page - only the content.
best,
Anton
Hi Anton,
Thank you for coming back so fast.
Unfortuantely it is not the modules that is causing the issue it is the widget container wrapper. Below is an example of what I currently have and the wrapper is removed from the module perfectly as you have suggested in your answer.
{% widget_container "title_row_container" label="Page title module" %}
{% module "module_123456" path="/path/to/module", label="Test Row", no_wrapper="true" %}
{% end_widget_container %}
However, what I need is for the widget_container wrapper to be removed as this is surrounding all the module content in a span which then isn’t correct markup as per this image below.

Is there a way to either remove the wrapper, like with the module, or at the very least change the span to a div?
Hello @Julian1936,
I’ve been recently working of different DND templates and unfortunately I believe it’s not possible to remove the extra markup created by sections, columns and rows.
Those elements were a bit of a headache for us also and since we couldn’t remove the markup we managed to display everything properly by working on the CSS of our theme.
If it’s affecting your modules and/or page, I recommend you to do the same and make sure that those elements won’t affect your layout by updating your CSS.
I know it’s not ideal but it’s what we have to work with ![]()
Hi albertsg,
Thanks for your response. As both you and Anton have stated the only real solution to my problem is to convert to DND templates and just hope the client doesn’t do anything too crazy.
Thanks to both of you for coming back so quickly.
Hi @Julian1936,
are you working with “old” templates or why are you using
{% widget_container %}
...
{% end_widget_container %}
To be honest - I have never used them. Either
{% dnd_area 'Some name' %}
...
{% end_dnd_area %}
or
<div class="customClass">
...
</div>
Regarding the span wrapping. I’ve tested it, doesn’t work.
What you could - but shouldn’t - do is rewriting every span with class “hs_cos_wrapper” with jQuery/JavaScript.
I highly advise you not to do so - since this can have massive negative impact on page speed/performance
But If you want to try it here’s a basic jQuery version which you can drop into your base.html/layout.html
{% require_js %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script>
$(".hs_cos_wrapper_widget").unwrap();
var $span = $("body span.hs_cos_wrapper");
$span.replaceWith(function () {
return $('<div/>', {
class: '',
html: this.innerHTML
});
});
</script>
{% end_require_js %}
best,
Anton
Hi Anton,
Again thanks for the response.
Thank you for the javascript solution but I’d already ruled that out as bad practice.
The reason I’m using them is to have a flexible column that allows for change the vertical position of an element without the possiblity of adding accident columns left and right. I started out using the DND Area but it allows both horizontally and vertically positioning and caused the client a lot of headaches.
The DND Area also adds a lot of unnecessary code around the module. Is there a way to lock it so it only has vertical postioning and so that it has less of the wrapping code?
Thanks again for all the advice