Often you’ll want to reuse Fragments or re-purpose some of the code from Fragments in another Site or somewhere else altogether. Since all the content is plain text, copy/pasting your code would always be an option, but there’s provides a much more elegant solution: exporting your Fragment Collections.
Exporting Fragments
There are two ways to export Fragments:
-
Export a single Collection.
-
Export some Fragments outside of a Collection.
To export a single Collection,
-
Go to Site Administration → Build → Page Fragments.
-
Next to Collections click Actions (
) and select Export.
-
Select a Collection or multiple Collections to be exported. Each collection exports in a separate file.
Figure 1: Select Collections to export.
Each Collection .zip
contains all data for the Collection as well as the
Fragments within it.
To export individual Fragments,
-
Click on the Collection that you want to export the fragment from.
-
To export all Fragments in the Collection without exporting any Collection data, click Actions (
) Export next to the Collection name. A
.zip
file is generated and downloaded automatically.Figure 2: Exporting all of the Fragments in a Collection.
-
To export a single Fragment, click Actions (
) Export next to the Fragment. A
.zip
file is generated and downloaded automatically.
When you export a single Fragment or a group of Fragments without a collection, you must have an existing Collection to import them into.
Now that you’ve done all this exporting, it’s time to import it all back it.
Importing
There are a few options for importing fragments, depending on how you exported them. You can import a Collection that was created in Liferay DXP, a Collection created using external tools, or any number of Page Fragments without a collection. Any time you import any Page Fragments they aren’t available for use until you have gone to each imported fragment and approved it for use. This is to ensure that there are no errors in any imported fragments before they are added to a page.
See Developing a Fragment Using Desktop Tools for more information on creating and importing Fragments using other tools.
Importing Collections
You can import collections that were exported from Liferay DXP or that were created using other tools. To import a collection, follow these steps:
-
Go to Site Administration → Build → Page Fragments.
-
Next to Collections, click Actions (
) and select Import.
Figure 3: Importing and exporting Collections is accessed from a single menu.
-
On the next screen, click Choose File and select the file you want to import.
-
If you want to replace an existing collection, make sure the box is checked for Overwrite Existing Files.
-
Click Import and the collection is uploaded.
Importing Individual Page Fragments
You can also import a single Page Fragment or a set that was exported outside of a collection.
-
From the root level of the Fragments page, click on an existing Collection where you want to import the Fragments.
-
From inside the Collection click the Actions (
) button in the top right corner of the page.
-
Select Import.
-
Drag-and-drop or click Select to upload the Fragments
.zip
. -
Click Import
The Fragments are imported into the Collection where you performed the import.
Export and Import let you use your preferred developer tools or share Fragment functionality elsewhere.