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
[QUESTION]: 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
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
Embed GrapesJS in Your SaaS: A Weekend Guide
Embed GrapesJS in your SaaS and ship a white-label page builder over a weekend. Honest tradeoffs, real code, and the plugins that close the UX gap.
Tutorial
Big Updates: TinyMCE 8 and Placeholder 2.0 for GrapesJS
In May we shipped major updates to two of our most popular GrapesJS plugins — TinyMCE Inline Text Editor and Placeholder.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.