How to wrap component with text nodes based on trait?
You just have to extend the toHTML function of the component model to achieve it (search in issues if you need examples)
Read full answer below βQuestion
Hello @artf , I'm not sure if this goes here but I can't figure out from the documentation how to update the component model based on a trait. The functionality I'm trying to achieve is add a text trait to a component called "condition" which would accept a Boolean expression. If this trait has a value then I would like to wrap the component with a text node like so: Example 1 component without trait would render like so: Example 2: component with trait value would render like so: Also, I'd like to exclude the wrapper text nodes in example 2 from the view if possible. I've been working on thi...
Answers (2)
You just have to extend the toHTML function of the component model to achieve it (search in issues if you need examples)
Ok, I will take a look. Thank you!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3170
Add class name from traits
Hello, what i am trying to achieve is to have the text component extended by assigning an extra trait named Alignment and deciding through...
Issue #2504
How to extend the image asset type to add custom attributes?
Hello, I'm trying to make a simple modification to the default image asset and am running into a wall, and am sure I'm missing something si...
Issue #2279
How to update the model for a custom component when a trait is changed.
Hi! I have read and re-read the GrapesJS Docs and API Reference on how to create a custom component and I just can't seem to figure it out....
Issue #3309
TextNodes interfere when changing content on element
Version: 0.16.44 Hi @artf I have a custom block with a custom button component, which its content is similar to this one. <a data-gjs-type=...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins βPremium plugins ship with support, regular updates, and production-ready features β save days of integration work.
Browse premium plugins βRelated tutorials
In-depth guides on the same topic.
Tutorial
Vanilla GrapesJS vs GrapesJS With Plugins: What You Actually Get Out of the Box (2026)
New to GrapesJS? See exactly what the stock editor gives you, where it falls short, and which plugins close the gaps β a beginner-friendly 2026 comparison
Tutorial
Lighthouse for GrapesJS: Audit Accessibility and SEO Without Leaving the Editor
Live WCAG 2.1/2.2 accessibility auditor + SEO manager for GrapesJS. Every finding is bound to the exact component β click to select, then one-click fix.
Tutorial
GrapesJS DevTools: A Developer Panel Inside Your Editor
If you've ever debugged GrapesJS with console.log(editor.getSelected()) and a dozen throwaway event listeners β this post is for you.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.