Using the Fragments Editor

Using the Fragments Editor

Liferay DXP includes a built-in editor for developing Content Page Fragments. To access the editor, open the Site Menu (Site Menu) and go to DesignFragments. From here, you can view, manage, and create Fragments and Fragment Sets.

note

For Liferay DXP 7.4+, Fragment Collections are called Fragment Sets in the Liferay UI.

Creating a Fragment Set

Before creating new Fragments, you must first create a new Fragment Set to put them in:

  1. Open the Site Menu, and go to DesignFragments

    note

    In Liferay DXP 7.1 and 7.2, open the Product Menu, and go to SiteSite BuilderPage Fragments.

  2. Click the Plus button (Add Button) next to Fragment Sets.

    Click the Plus button nest to Fragment Sets.

  3. Enter a name and description for the new Set.

    tip

    Create Sets that group Fragments by functionality or by teams and departments.

  4. Click Save.

Once saved, you can add Fragments to the Set.

Creating a New Fragment

Follow these steps to create a Fragment:

  1. Go to the desired Fragment Set and click the Add button (Add Button) to create a new Fragment.

    Go to the desired Fragment Set and click the Add Button.

    note

    Prior to Liferay DXP 7.3, a Fragment could either be a Section or a Component. In Liferay DXP 7.3+, all Page Fragments are Components.

  2. Enter a name for the Fragment and click Save.

    Enter a name for the new Fragment.

  3. In the Code tab, use the CSS, HTML, and JavaScript fields to add your Fragment’s resources. Here, you can also see a live preview of your Fragment’s appearance in different device contexts.

    Here are some HTML editing shortcuts:

    • Enter an open angle bracket (<) to access standard HTML tags and Liferay’s Fragment-specific tags.

    • Start an element attribute with data to access Liferay’s editable Fragment attributes .

    Liferay's editable Fragment attributes are available in the editor.

    The example below adds a Card component with editable text:

    <div class="marketing-card-fragment-01">
      <div class="card">
        <lfr-editable id="01-card-image" type="image">
          <img src="https://cdn.dribbble.com/users/1408464/screenshots/9323535/media/a5b9a76256562e878ecc6dc5cd0fadf0.png" class="card-img-top" alt="2020 - Try New Things">
        </lfr-editable>
        <div class="card-body">
          <lfr-editable id="02-card-title" type="rich-text">
            <h5 class="card-title">Editable Card title</h5>
          </lfr-editable>
          <lfr-editable id="03-card-text" type="rich-text">
            <p class="card-text">Here is some editable text.</p>
          </lfr-editable>
          <lfr-editable id="04-card-link" type="link">
            <a href="#" class="btn btn-primary">Editable link</a>
          </lfr-editable>
        </div>
      </div>
    </div>
    
    .marketing-card-fragment-01 .card img {
      max-width: 100%;
    }
    

    Add CSS, HTML, and Javascript resources to the Fragment and see a live preview.

  4. In the Configuration tab, use the JSON field to add configuration options to a Page Fragment.

    Add configuration options to a Page Fragment.

    tip

    You can add a configurationRole value to any field set (alongside the fields object in the JSON) to specify which tab the associated fields appear in. Set the value as styles to make the fields appear in the Styles tab, or set it to advanced to make them appear in the Advanced tab (only in Liferay DXP versions U23+ or GA23+). If no configurationRole is set, then they appear in the General tab by default.

  5. Click Publish to save your Fragment and make it available for use in Content Pages.

    The Fragment can be used in Content Pages.

While developing a Fragment, changes are automatically saved as a draft until your Fragment is published. Once added to a Set, you can copy, export, edit, and remove a Fragment at any time in the Fragments editor. See Managing Fragments for more information on available actions for Page Fragments.

note

Since Liferay DXP 7.2 SP1+ and Liferay Portal 7.2 GA2+, you can create Page Fragments on the Global Site to make them available for all Sites. To expose this feature in the initial releases of these versions, you must create a .config file named com.liferay.fragment.web.internal.configuration.FragmentGlobalPanelAppConfiguration.config and add the enabled=B"true" property. Then copy it to your Liferay DXP instance’s osgi/configs folder. Global Page Fragments are inherited by child Sites and can only be edited from the Global Site. Any resources the Global Page Fragment references from the Global Site are copied to a Site that leverages the Page Fragment.