RE: Create Fragments Using Theme In Liferay 7.1

meet soni, modified 7 Years ago. New Member Post: 1 Join Date: 7/17/17 Recent Posts

I want to add fragments using theme in liferay 7.1 but I'm not able to find any documentation from which I can add fragments in theme.

 

I've seen that in liferay 7.1 themes(Liferay Westeros Bank Theme) they have imported fragments in which they've created 
Site Initializer module, so is this the only way to import fragments using theme and if yes then how can I create such type of site initializer module in my custom theme?

thumbnail
Pasi Kössi, modified 6 Years ago. New Member Posts: 12 Join Date: 10/13/08 Recent Posts

It seems writing a SiteInitializer implementation is now the preferred way, as even ResourceImporter has been deprecated in 7.1. The interface is in the source tree: https://github.com/liferay/liferay-portal/blob/master/modules/apps/site/site-api/src/main/java/com/liferay/site/initializer/SiteInitializer.java.

I guess you can have a look at how Fjord theme has implemented the interface, but bear in mind the license implications if you plan to use that code as a basis.

thumbnail
Olaf Kock, modified 6 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts

Be aware that the site initializer is still evolving - it's undocumented because the API isn't fully baked.

ResourceImporter, while deprecated, are still (typically) the way to go when importing content. However, in the case given (for fragments) I'd just model it all along what you find in Liferay's themes on github. Just be aware that this is not yet a stable API and it might require some work to adapt to newer versions of site initializers, especially once you upgrade to 7.2, but maybe earlier.

Another way is to not bundle your fragments in your theme, but provide them as separate export. The export format is a zip file that you can easily inspect and create manually as well.

Disclaimer: This is my personal understanding of the differences between ResourceImporter and SiteInitializer.