Skip to main content
Level 2
Mar 27, 2025 9:58 AM UTC

Dynamic styling of CSS using Style Tag Visual studio Code css-identifierexpected warning

Hi,

I ve got the following code in one of my custom component html templates:

<style data-sly-test="${formInput.getGrowFactor}"> #${formInput.name @ context="styleString"}Id${formInput.uniqueId @ context="styleString"}Wrapper { flex-grow: ${formInput.getGrowFactor @ context="styleString"}; } </style>


the code itself is working, but my IDE Visual Studio Code is generating the following errors:
css-identifierexpected
css-propertyvalueexpected

Looks like htl  ${} syntax is not compliant with some other validation tool.

Anybody knows how I may get rid of these errors ?

Thanks a lot for your support in advance.

 

--

volker
 

5 replies

arunpatidar
Community Advisor
Community Advisor
Mar 27, 2025 11:22 AM UTC

Hi @vhochsteintef 

You can create the whole CSS rule as string in Sling Model and return it to HTL to make whole logic simplified

 

Sling Model

return String.format( "#%sId%sWrapper { flex-grow: %s; }", name, uniqueId, growFactor );

 

HTL

<style data-sly-test="${formInput.generatedStyle}"> ${formInput.generatedStyle @ context='styleString'} </style>

 

 

 

Translate
Arun Patidar
Level 2
Mar 27, 2025 1:06 PM UTC

Hi Arun,

thanks a lot for your suggestion.

Your version generates the following errors:


Unfortuently, it s not solving the issue. 😞

--

volker

Translate
kautuk_sahni
Level 9
Apr 8, 2025 11:24 AM UTC

@vhochsteintef Did you find the suggestions helpful? Please let us know if you need more information. If a response worked, kindly mark it as correct for posterity; alternatively, if you found a solution yourself, we’d appreciate it if you could share it with the community. Thank you!

Translate
Kautuk Sahni
AmitVishwakarma
Community Advisor
Community Advisor
Mar 27, 2025 6:30 PM UTC

Hi @vhochsteintef ,

The issue arises because HTL expressions (${}) inside the <style> tag are not recognized as valid CSS by Visual Studio Code’s CSS validation engine.

Even though your code works fine in AEM, VS Code is treating it as invalid because the ${} syntax is not standard in CSS.

Solution 1: Disable CSS Validation in VS Code

Since this is a false positive, you can disable CSS validation for your workspace:

Open VS Code Settings (Cmd + , on Mac or Ctrl + , on Windows).
Search for css validate.
Find CSS › Validate: Enable and uncheck the box (or set to false in settings.json):

"css.validate": false
Translate
Amit Vishwakarma - Adobe Commerce Champion 2025 | 17x Adobe certified | 6x Adobe SME