We have a Liferay portlet application with many different portlets deployed.
If have a single portlet that needs a static .js file served how can I add this to only the portlet in question?
Previously we had added .css/ and .js files included by portlets to the theme. In this case only one portlet needs this file. Is it possible to include this file and serve it statically within a .war deployed for a single portlet?
You can declare required JS or CSS files in liferay-portlet.xml. This file has options for adding them to the header or footer of the page. Look up the very well documented DTD of that file to figure out the options and positions.
You can also do as you suggested in put the js file in a 'static resources portlet' to be consumed by all of your other portlets like a simple CDN.
Remember that to access the js file you will need to hit the portlet context so: localhost:8080/static-resources-portlet/js/awesome.js
Related
I have A Custom Theme project & A Custom portlet project in liferay.
I want to call a custom action which is in Custom portlet from navigation.vm File of Theme Project.
actionurl is : /c/journal/upload_article which is called from same portlet project successfully.
How to call this from theme project?
Any help is really appreciated.
It sounds weird to "call" an action from a theme. If you embed a form to upload content on every page, naturally, you'd need a target for the upload. But still, the theme seems to be the wrong place to do so.
Nevertheless: It seems that you're using a non-custom URL for uploading (/c/journal/upload_article). You can do so from wherever in HTML. The big question then is: Where will you end up after the upload, as it doesn't happen from within a page.
If you need a proper portlet URL on an individual page, and want to return to the same page, the best way forward is to embed a portlet in the theme (which makes a great search term for Liferay's documentation). From that portlet you can utilize Liferay's API to do what you're trying to achieve. Make it a very lightweight portlet, because, well, it will be embedded on every single page.
I would like to know whether Liferay can divide email templates into logical sections and manage these sections. Furthermore I would like to manage the email templates with Liferay's content management system.
Liferay contains email template in tmpl files, which are not manageable like WCM, So in case if you want to change or manage that templates then you need to create class level hook. For that you have to create a path in hook xml, which indicate that your template will placed in /root/web-inif/classes folder of tomcat server. then need to restart your server. After that your changes will reflect.
XML file path.
\ROOT\WEB-INF\
and hook folder structure will be upto the classes folder.
I have created a theme which has few referenced plugins and CSS (jQuery, bootstrap etc). These files are present in WEB-INF folder. I'm creating a XPage by using these files and want to make this page available to anonymous users. I have tried "Allow Public Access" to specific XPage but that doesn't solve my problem because CSS doesn't apply to the page. How can I solve this issue.
Add the files as Resources - Files design elements. You can control public access for these design elements.
You can also use the CSS and Script Libraries design elements for this.
Update: You can mimic a directory structure in Files by using "/". For instance, using "css/main.css" as the file name for a CSS file makes it possible to reference it as being in a directory called css. So the following stylesheet reference in XPages will work:
<xp:styleSheet href="/css/main.css"></xp:styleSheet>
WEB-INF is not exposed to the outside. WebContent (the parent folder) is. Unless your whole app provides Anonymous access follow Per's suggestion and use the Design elements.
If you need a file structure in those, use webdav access when copying - or add the Navigator view and use import
Thank you for suggestions #Tim, #Per Henrik & # stwissel. For now i have moved all my files to other database where i have anonymous reader access. Upon successful login i'm redirecting it to my current db.
Is there a way to include Liferay document or web-content structures and templates in portlet plugin war files and have them become available to users like the standard ones are?
The use-case would be that you are writing a portlet that takes advantage of a custom Document Library structure that you are providing. But you don't want to distribute this structure as a separate thing with its own installation procedure (such as providing a LAR just for the structure), you just want your plugin to make the custom structure available whenever it is installed.
You can achieve your goal by adding a portal.properties file to the WEB-INF/classes directory of your portlet. This file should contain the following line:
application.startup.events=com.yourcompany.whatever.YourCustomStartupAction
This custom startup action should be a class that extends from com.liferay.portal.kernel.events.SimpleAction. In it you will be able to leverage all the Liferay service utils to do things in Liferay at the moment your portlet is started. The class you need to use to work with the Liferay document library specifically is DLAppLocalServiceUtil. This util class has all the necessary methods to work with files/folders in the document library.
For web content related stuff, such as structures, templates and articles, just use JournalStructureLocalServiceUtil, JournalTemplateLocalServiceUtil and JournalArticleLocalServiceUtil.
I hope i got your question right ;)
You could create the folder Structure via the DLFolderService when the portlet is deployed.
To run a method when the Server starts you will have to use the CustomAction i think, check it out : here
I want to create a common properties files which can be shared across 2 portlets in Liferay.
Or rather where can it be put so that all the portlets can access the same file.
If you have two portlets in the same WAR then you can have a common property file for both in WEB-INF/src folder of your portlet and access it using com.liferay.util.portlet.PortletProps class like:
PortletProps.get("propertyName")
If your portlets are packaged in separate WARs then you have to place the property in portal-ext.properties and access the property using com.liferay.portal.util.PropsUtil.get("propertyName").