Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Unable to apply component-level CSS.

Avatar

Former Community Member

Hello,


I'm trying to add CSS for a component.  I've created a cq:ClientLibraryNode and then created two new files under it >> css.txt and component.css.  Please advise how to load this file for the component as the styles in component.css are not getting applied.

Thanks in advance.

Regards.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi,

Assuming that you have created your clientLibs under /apps/yourProjectFolder which might be root cause of your styles not being loaded. Creating component level clientLibs has few downsides such as below -

The resources are retrieved from /apps, but /apps will have to be blocked on the publish instance which might be the reason behind your css styles not being loaded. For this to be resolved, we will have to redirect resources via /etc/designs and merge into single files. Please refer below community article for clear understanding. This talks about :

1. Components with their own Javascript and CSS files

2. Global Javascript and CSS files

So here, you can learn to create a component specific javascripts/css and global javascripts/css.

http://blogs.adobe.com/experiencedelivers/experience-management/clientlibs-explained-example/

Note:

For example - To include a client lib that contains JQuery Libs/CSS - you would use:

<sly data-sly-use.clientLib="${'/libs/granite/sightly/templates/clientlib.html'}" data-sly-unwrap/>

<sly data-sly-call="${clientLib.css @ categories='myproject.components'}" data-sly-unwrap/>

<sly data-sly-call="${clientLib.js @ categories='myproject.components'}" data-sly-unwrap/>

Also make sure that you will have to you will have to register your component.css in css.txt file as shown below:

#base=css

component.css

Regards,

TechAspect Solutions

View solution in original post

6 Replies

Avatar

Level 10

A client library will not be loaded unless you embed it or call it template include or define the same category which is being already loaded by someone

I think you are looking to embed this into main client lib.

Go to project global client lib and add a property embed with value as the category of component client lib.

https://docs.adobe.com/docs/en/aem/6-3/develop/the-basics/clientlibs.html#Embedding Code From Other Libraries

Thanks

Avatar

Correct answer by
Level 7

Hi,

Assuming that you have created your clientLibs under /apps/yourProjectFolder which might be root cause of your styles not being loaded. Creating component level clientLibs has few downsides such as below -

The resources are retrieved from /apps, but /apps will have to be blocked on the publish instance which might be the reason behind your css styles not being loaded. For this to be resolved, we will have to redirect resources via /etc/designs and merge into single files. Please refer below community article for clear understanding. This talks about :

1. Components with their own Javascript and CSS files

2. Global Javascript and CSS files

So here, you can learn to create a component specific javascripts/css and global javascripts/css.

http://blogs.adobe.com/experiencedelivers/experience-management/clientlibs-explained-example/

Note:

For example - To include a client lib that contains JQuery Libs/CSS - you would use:

<sly data-sly-use.clientLib="${'/libs/granite/sightly/templates/clientlib.html'}" data-sly-unwrap/>

<sly data-sly-call="${clientLib.css @ categories='myproject.components'}" data-sly-unwrap/>

<sly data-sly-call="${clientLib.js @ categories='myproject.components'}" data-sly-unwrap/>

Also make sure that you will have to you will have to register your component.css in css.txt file as shown below:

#base=css

component.css

Regards,

TechAspect Solutions

Avatar

Former Community Member

Hello smacdonald2008​,

The article you have linked is about Sling Servlets . Request you to update with the correct link.

Thanks & Regards

Avatar

Level 10

In this article, we have site.css, which makes page component blue background. Look how we reference it. This will help you understand how to get CSS at component level...

Adobe Experience Manager Help | Creating custom Adobe Experience Manager email services