How to include static resources (CSS/JS/Images) in Liferay OSGI module

Leave a Comment
How to include static resources (CSS/JS/Images) in Liferay OSGI module As you know development approach has been completely changed with Liferay DXP. In older version of Liferay it was easy to include static resource like CSS , JS and Images as part of portlet but with Liferay DXP you have to do few additional changes to include them.

First of all you need to add webcontext path in your modules bnd file.

Web-ContextPath: /my-custom-portlet



After adding web context path you can add static resource inside META-INF folder.

main\resources\META-INF\resources\css

You can access CSS files added in above folder by adding following line in your code.

<link href="/o/my-custom-portlet/css/my-custom.css" rel="stylesheet" type="text/css"  />

Similar way you can add and use other static resource like JS and Images.

Read other posts on Liferay DXP

How To Read Portlet.Properties File In Liferay DXP
How To Include Custom Portlet In Theme - Liferay DXP
How To Specify External Jar Dependency In Liferay DXP
How To Specify Module Dependencies In Liferay DXP
How To Disable Re-Indexing Of All Journal Article Versions In Liferay DXP

Next PostNewer Post Previous PostOlder Post Home

0 comments:

Post a Comment