How can I create Liferay web content structure's outside of Liferay configuration? - liferay

I'm very new to Liferay theme development and i'm trying to find the most optimal workflow for development.
So I've been experimenting with creating Web Content Templates and Web Content Structures within Liferay CMS configuration.
What I would ideally like to do is create my view "Web Content Structure" outside of Liferay configuration and instead have it as a view/template inside my theme files so that I can have my code peer reviewed and version controlled in Bitbucket.
Is this possible?
Alternatively is there a way to output the values of a given web content instance within my theme?
I'm building a theme for Liferay 7 by the way.
Thanks in advance
Richard

You can copy and paste the structure when you create them form the LFR editors into your source code repository.
Also if you know how to define the JSON you can do it straight in the file. The free market templates are even easier to edit in file format. When you're done, you need to go and upload the artefacts to the portal via the editor/file upload option.
You can't stick it into the theme because that approach would not allow you to do updates.
You can search for a community plugin or write your own one that would do structure/template updates during deploy.

Related

Liferay Portal customization

I'm new to the Liferay Portal and I have been assigned to develop a Liferay application with the following structure:
logo
search bar
result list
We plan is to sell the application to different customers so the resources like images (logo and so on) and css need to be customizable. According to this tutorial resources like images and style sheets are part of the portal apps which are deployed to Liferay. So in my case for 2 different customers I would need 2 different app versions. Instead I'd like to have one version of the portlet which would load all the resources from a database (maybe via a rest call to an appropriate configuration service). That would give us an opportunity of a better provisioning.
Furthermore I'd like to be able to share css resources between different portlets.
Any ideas how I can achieve this 2 goals?
You seem to be talking about themes. You need to create a Liferay Theme. You can Extend an existing Liferay theme or create a brand new. Themes are like portlets meaning you deploy them the same way only they are specific for what you seem to be descibing. Take a look at https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/theme-builder.
Here you have lots of examples https://github.com/liferay/liferay-plugins/tree/master/themes and scripts for generating new themes.
Hope it helps
As Sudakatux said, you're talking about themes. I'd just like to add a couple of things:
If you're talking about styling portlet content (i.e. what should it look like when you display content in a portlet), you want to search for Application Display Templates (see links below).
If you're talking about styling portlet itself, i.e. what it looks like when you place portlets on your LR, you can do that within a theme.
Themes in Liferay 6.2 and 7.x are incompatible. You tagged the question LR-6 and LR7; I'd recommend choosing one (LR7 is vastly easier and faster to develop themes for, in my experience)
If you are creating your own portlet, and you want to style the content of your own portlet, you'll have to do that within JSPs. Edit: You can also use Freemarker with your portlets; however, I personally still prefer JSPs due to the sheer power of what you can do within it.
Useful links:
Liferay 6.2 Lunar Theme tutorial - shows how to create and deploy LR 6.2 theme
Liferay 7 Theme sample - LR7 has a Blade project that shows a lot by example. You can change Maven to Gradle and vice versa. Very useful.
Application Display Template LR7
Application Display Template LR6
This is how your theme directory structure should be laid out in Liferay 7 DXP. Make sure though you create a Liferay Workspace and create a Liferay module ( theme ) in that workspace. If you do not, you will have lots of errors and cause yourself much confusion.
You can put all your css changes in the _custom.scss file and they will overwrite the default css styles.
Blade CLI will generate the core freemarker templates. I recommend a header/footer template as well.
Lastly, this is how you reference the logo in your freemarker template
<a class="${logo_css_class}" href="${site_default_url}" title="<#liferay.language_format arguments="${site_name}" key="go-to-x" />">
<img alt="${logo_description}" class="logo1" src="${site_logo}" />
</a>

Automatic way of export / import pages from liferay

I have created portlets for liferay and prepare couple of pages. Now I want to create installation script, which create pages definition in customer liferay server. I know that pages export/import is possible using LAR file, but this could be done only manualy, or using remote publishing which i am not able to do.
I was searching on net and found ddm tool. Which should be able to do that. Unfortunately i'm not able to get it work as it export only web content, blogs, wikis, etc, but not pages with portlets. It is probably because one of the condition is "Every Template must be assigned to a Structure. Don't create any templates on the Liferay server which does not have a structure connected to it.
". But how can I assign page to structure ? Cant find anything.
Or is there any other option for automatic page creation, which could be used ?
In case you created a custom theme, you can easily use the "resources importer" to create an entire site via the "sitemap.json" file (define pages: choose layout, assign portlets to the columns, ...). You can also export existing content as xml from the current instance and import them via the theme. Same thing for web content structures and templates.
for more details: https://dev.liferay.com/develop/tutorials/-/knowledge_base/6-1/importing-resources-with-your-themes
Unfortunately theme is produced by another supplier, so this solution isn't suitable for me.
at the end i find working solution which consist of following steps:
create plugin hook
in hook setup upgrade process
in the upgrade process create pages with appropriate layout, friendlyUrl, etc. All these is possible to do using liferay api
Don't have enough reputation, so at least two links
https://www.liferay.com/de/web/james.falkner/blog/-/blogs/7cogs-is-dead-long-live-7cogs-
https://github.com/azzazzel/liferay-official-plugins/tree/master/hooks/sevencogs-hook/docroot/WEB-INF/src/com/liferay/sevencogs/hook/upgrade

Liferay create site / page programmatically

I have been using Liferay for work for 2 weeks. I noticed that it's a bit difficult to find good documentation and tutorials.
Until now I created pages from the web portal. After I create them, I drag and drop portlets. I don't really like this approach, I would prefer to use a coding approach. Is there a way to create a website or page programmatically by defining a project as I do to create portlets?
Moreover, I am using Liferay with WebLogic 10.3.6. I want to know where liferay puts pages I created via web-portal on the file system. I suppose that a file, or something similar, is created when I declare a new site on the Liferay web-portal.
Thank you all,
Marco
Yes Liferay has it's Database, all data of any Liferay object is stored in the database and / or on the file system depending on your configuration.
However, one of the functionality of Liferay is to let you create pages / sites through the UI. As documented in the Java Portal Specification and Liferay Server Documents your approach to create pages in an alternative way is possible but it is part of Liferay's Portal Services. You can use Liferay's Service (HTTP REST) API to call the related service. To access those APIs you need to configure your Liferay Server.
In case you want to do programmatically you still need to configure, enable and call those external HTTP services from your code. You should not create Liferay Objects from your own code hosted as an extension inside your Liferay Instance as that will result inconsistency in your Liferay Database / filesystem. (As in case of page creation Liferay creates a set of other related objects in it's database / filesystem.)
In your liferay bundle you will find two plugins of interest.
First is resources-importer-web for which description says
The Resources Importer app allows front-end developers to package web
content, portlet configurations, and layouts together in a theme
without saving it as a compiled .LAR file thereby allowing for greater
flexibility in its usage between Liferay Portal versions.This app will automatically create associated content when other
plugins are deployed that are configured to make use of the Resource
Importer app.This app installs as a Liferay service.
Second is welcome-theme which declares resources to be created by resources-importer-web. This on should be example how to create your own. Take a look at
welcome-theme\WEB-INF\src\resources-importer\*
welcome-theme\WEB-INF\liferay-plugin-package.properties
This feature is described at importing-resources-with-themes
As mentioned by gabor_the_kid, Liferay stores all objects in its tables. For example, User related objects would be in user table. Liferay exposed services or API's to change the default/to add new behaviors by program but not easier than achieving it through UI. Also maintenance should be considered for going program way of creating pages or layouts etc.
You can describe your changes using xml and use the Liferay Portal DB Setup core to create the changes in DB.
The library defines the list of available xml configurations.

Which is the Liferay equivalent of a IBM WebSphere Portal / WCM Menu?

I've developed with WPS and WCM for several years and now I am also learning Liferay. I can't help but compare the features and I understand that in Liferay some things are done differently.
I would like to know the best practices to manage the following simple example:
A simple page with a carrousel with several images and links
Google analytics inserted in the page (Reusable in most pages)
The following is how I'd solve it in IBM WPS:
A HTML component with the Google Analytics code that is called in every page (I can't find how to do this in Liferay)
A content definition of an image and a link.
Create several contents for each image and link.
Create a menu that shows the list of content in the form of a carrousel (I can't find how to do this either in Liferay)
I am aware that Liferay has a list portlet and content that has repeatable items. I know I could use these, however its much more usable if I can have on content for each image/link and one reusable HTML snippet of code.
How should I solve this in liferay in the most efficient way?
Thanks!
You have to use Liferay Web Content portlet for creating the carousel. This is available in Control Panel. For your particular requirememnt you have to create a dynamic web content, which involves using of Velocity language and javascript to iterate over a set of images. Infact if you see Liferay's website, the home page has this kind of stuff.
For Google Analytics there are two ways. Liferay is not just meant for creating one site, it caters creation of multiple sites. Each site has a group of pages. You can create site from Control panel again. In the site settings you have this option to add google analytics id. So with each site can have different google analytics id.
If you want to do it at a global level, we add the google analytics script snippet in the Theme of liferay.
To get a better understanding of all the jargons used in Liferay, you have to atleast go through Liferay's documentation. And while going through it you have unlearn what you have previously learned. Liferay has hell lot of features than Websphere portal.
http://www.liferay.com/documentation/liferay-portal/6.1/user-guide

Setting up a new website with Liferay Portal - basic steps?

I know this is not specifically a programming question, but programmers will often have to do this work.
How do I create a website with Liferay portal - the docs are pretty light on this fundamental issue and are all for version 4.4. I am using version 5.2 and the docs don't seem to be relevant.
Do you know what the basic steps are. So far I have logged in as the bruno user and can see the 7cogs website and edit it. But I now need to create my own website (for my company) and be able to develop portlets to add to the parts of the page.
Further I notice that the docs talk about doing work in Eclipse. If our website is all static HTML, (the reason we want liferay is mainly so that we can edit content items using its content management tools), then will there be any need for Java dev, or will it all be drag n drop and clicking to get setup. Any guidance will be much appreciated.
Liferay can be used as a simple CMS, without much Java knowledge : creating, editing and positioning of web content fragments are drag'n'drop and use of the included rich text editor.
But to start using Liferay for your company, there are two main steps : a technical configuration (database, etc.), and a look'n'feel customization.
The technical part
First of all, you should get rid of the 7cogs website : this is called a hook in the Liferay wording. To do that, if you are using Tomcat for the application server, just delete the 7cogs directory as stated here.
You can now create the configuration file for your installation : it's a simple text properties file, named portal-ext.properties and placed in the webapps/ROOT/WEB-INF/classes folder of your tomcat installation.
This file handles most of the configuration of the Liferay portal, for example :
the name of your company
if you want to display a terms of use page on first login
if you want anybody to be able to create an account on your portal
the database where the data will be stored
To do this, the properties in the portal-ext.properties override default properties found in a embedded portal.properties file located in the jar file portal-impl.jar, in the webapps/ROOT/WEB-INF/lib directory. Just unzip the jar file in a temporary folder to access the portal.properties file.
A sample portal-ext.properties file :
company.default.web.id=yourcompany.com
terms.of.use.required=false
company.security.strangers=false
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=root
Once done, you can startup your application server. As the default admin (named test, something you can change in the portal-ext.properties file), you can access to the centralized web "control center", located in the "dock" (the strange menu labelled "welcome Test" in the upper right part of any page once logged in).
I would advise you to read the administration guide, useful for most administrative tasks.
The "branding" part
Liferay uses "Themes" to automatically decorate the portal pages (logo, navigation, portlet borders...) using images, CSS, Javascript (JQuery) and the templating language Velocity. The themes are bundled in a .war file, like a standard web application, and deployed on the fly either via the control center or by dropping the file in the deploy directory of the server.
Liferay can use several themes at the same time, one for each community (a group of pages, users and content) for example.
Creating your own theme can be done afterwards, using the "Plugins SDK".
The Wiki, forums and blogs can be very useful.

Resources