When working with CMS items it would be great to sometimes be able to combine text fields from the CMS with static text. E.g. on a Services template page the H1 tag could then be. "We offer you {Name}"
Currently this is done by workaround by using HTML embed block, but this makes styling and use of classes much harder.
In other cases like adding alt text to an image block, there is no way to combine dynamic and static text.
Combining dynamic CMS text fields with static text can indeed make your content more personalized and engaging. Here are a few ways to achieve this more efficiently, depending on the platform you’re using:
Wix CMS Expressions
Wix has introduced a feature called CMS Expressions that allows you to combine static text with dynamic content from multiple CMS fields. This can be done without needing to use HTML embed blocks, making it easier to style and use classes.
Example: To create an H1 tag like “We offer you {Name}”, you can use the CONCAT function:
CONCAT("We offer you ", {Name})
This expression pulls the Name field from your dataset and combines it with the static text1.
Webflow
In Webflow, you can use the CMS to bind dynamic content to elements on your page. While Webflow doesn’t have a built-in expression feature like Wix, you can achieve similar results using custom code or third-party integrations.
Example: You can use custom JavaScript to combine static and dynamic text:
JavaScript
const name = document.querySelector('.cms-name').textContent;
document.querySelector('.h1-tag').textContent = `We offer you ${name}`;
Other Platforms
For other CMS platforms, you might need to use custom scripts or plugins to achieve this functionality. Here are some general steps:
Identify the Dynamic Field: Determine the CMS field you want to combine with static text.
Use a Scripting Language: Use JavaScript or another scripting language to concatenate the static and dynamic text.
Apply to Elements: Apply the combined text to the desired elements on your page.
Example for Alt Text
To add alt text to an image block that combines dynamic and static text, you can use a similar approach:
JavaScript
const productName = document.querySelector('.cms-product-name').textContent;
document.querySelector('.image-block').setAttribute('alt', `Image of ${productName}`);