Introduction page for day 2

Day 2 Exercises for Building Enterprise Websites with Liferay

Exercise 11a: Generating Content with ChatGPT

You may have noticed that web content articles include the AI Creator button for generating content using ChatGPT. Using this feature requires a valid API key.

Here you’ll add a temporary API key to your instance as the Clarity Admin user.

To do this,

  1. Sign in as the Clarity Admin user.

    • Username: admin@clarityvisionsolutions.com
    • Password: learn
  2. Open the Global Menu (Global Menu), go to the Control Panel tab, and click Instance Settings.

  3. Click AI Creator.

  4. Enter the API key provided for this training.

    Note: This key is temporary.

  5. Ensure these options are checked:

    • Enable ChatGPT to Create Content
    • Enable DALL-E to Create Images
  6. Click Save.

  7. Go to the Marketing Assets library and select Web Content.

  8. Click New and select Basic Web Content.

  9. Click the AI Creator button (AI Creator Button) to generate content.

    Use the AI Creator tool to generate content.

  10. Enter your desired description, tone, and word count.

  11. Click Create.

    This generates a text response.

  12. Click Add to copy the response into your web content.

    Alternatively, click Try Again to generate a new response.

Great! You’ve used ChatGPT to generate web content. Next, you can explore how to use AI to tag content or move to Lesson 12 and learn about how Liferay features can improve Clarity’s content management.

Exercise 11b: Auto-Tagging Content (Bonus)

You can manually tag most Liferay assets, but manually tagging content can be time consuming. Liferay also provides auto tagging features and integrations to simplify this process. By default, auto tagging is disabled.

Here you’ll enable text and image auto-tagging as the Clarity Admin user.

To do this,

  1. Open the Global Menu (Global Menu), go to the Control Panel tab, and click Instance Settings.

  2. Under Content and Data, click Assets.

  3. Click Asset Auto Tagging in the left menu.

  4. Ensure these options are checked

    • Enable Auto Tagging of Assets
    • Update Auto Tags
  5. Set the max number of tags to 3.

    Note: Leaving the field blank disables auto-tagging. Setting the value to 0 removes any auto limit.

  6. Click Update.

    Now that it’s enabled, we need to set up our tagging providers for web content articles and images.

  7. Click OpenNLP Text Auto Tagging in the left menu.

  8. Select Web Content Article in the drop-down menu.

    If the drop-down menu does not appear, enter com.liferay.journal.model.JournalArticle.

    Note: You can also click the plus button to enable OpenNLP auto tagging for additional types of text content (i.e., blog entries = com.liferay.blogs.model.BlogsEntry; documents = com.liferay.document.library.kernel.model.DLFileEntry).

  9. Click Update.

  10. Click TensorFlow Image Auto Tagging in the left menu.

  11. Check Enable TensorFlow Image Auto Tagging.

  12. Click Update.

    Tip: You can double check that all the settings are correct for the Clarity site by going to Site MenuConfigurationSite SettingsAssets and validating that auto tagging is enabled.

  13. Go to the Marketing Assets library and select Web Content.

  14. Click New and select Basic Web Content.

  15. Enter a title and use the AI Creator (AI Creator Button) to generate article content with over 500 words.

    For example,

    FieldValue
    DescriptionWrite a compelling article on the importance of annual eye exams is for ongoing eye health.
    ToneFriendly
    Word Count2000

    Important: The article’s title and content must be meaningful for auto-tagging to work. Do not use “Lorem Ipsum.”

  16. Click Publish.

  17. Begin editing the article. In the right side panel, you should see tags set for the content.

    Note: If you don’t see any tags, add more content to the article and click Update.

Exercise 12a: Creating a Vocabulary

Liferay provides vocabularies for categorizing content, making it easier to find and display the content you need.

Here you’ll define a vocabulary with categories for the FAQ web content as Christian Carter.

To do this,

  1. Sign in as Christian Carter.

    • Username: christian.carter@clarityvisionsolutions.com
    • Password: learn
  2. Open the Global Menu (Global Menu), go to the Applications tab, and click Asset Libraries.

  3. Select the Marketing Assets library and click Categories.

  4. Click Add (Add) next to Vocabularies to create a new vocabulary.

  5. Enter these details:

    FieldValue
    NameFAQ
    DescriptionCategories for FAQ articles.
    Allow Multiple CategoriesYes
    VisibilityPublic
    Asset TypesWeb Content Article
    SubtypeFAQ
    RequiredNot Required

    Choose which asset types the vocabulary will be associated with.

  6. Click Save to create the vocabulary.

You now have a vocabulary to contain FAQ categories.

Exercise 12b: Adding Categories to a Vocabulary

After creating a vocabulary, you can add categories and subcategories to establish the desired organizational schema for your content.

Here you’ll add categories to the FAQ vocabulary you created in the previous exercise as Christian Carter.

To do this,

  1. In the Categories application, select the FAQ vocabulary in the Vocabularies sidebar.

  2. Click New and enter Retail Partners for Name.

  3. Click Save to add the category.

  4. Repeat the above steps to add three more categories to the FAQ vocabulary:

    • Products & Services
    • Pricing & Ordering
    • Returns & Exchanges

    Create and use categories according to your content.

  5. (Challenge) Assign the correct category to each FAQ web content article. The FAQs are sorted into folders corresponding to their categories.

    Hint: Look in the Properties sidebar for each FAQ.

You have now defined and assigned categories to your FAQ web content.

Exercise 13a: Creating a Manual Collection

Liferay Collections are lists of content items that you can showcase in your site pages. You can group different content types together, making it easier to find and display related items. Each list can be defined manually or dynamically.

Here you’ll add web content articles to a manual collection and map them to Clarity’s home page as Walter Douglas.

To do this,

  1. Sign in as Walter Douglas.

    • Email: walter.douglas@clarityvisionsolutions.com
    • Password: learn
  2. Open the Site Menu (Site Menu), expand Site Builder, and select Collections.

  3. Click New and select Manual Collection.

  4. For Title, enter Helpful Articles and click Save.

  5. For Item Type, select Web Content Article.

  6. For Item Subtype, select Article.

  7. Click Save.

  8. In the Collection Items section, click Select and select Article.

  9. Go to the Articles folder, select these three articles:

    • Embracing Innovation: Key Trends Shaping Eyewear Manufacturing
    • Revolutionizing the Eyewear Industry: How Innovative Materials Make a Difference
    • Enhancing Efficiency in Eyewear Manufacturing: A Comprehensive Approach
  10. Click Add.

    Add the articles to the Helpful Articles collection.

    The manual collection is now populated with content and ready to use in site pages.

  11. Go to the Home page and click Edit (Edit Button).

  12. Select the Collection Display fragment in the Helpful Articles container.

  13. In the configuration side panel, click Plus (Plus Button) for Collection and select the Helpful Articles collection.

    Select the Helpful Articles collection.

    The fragment now sources its content from the Helpful Articles collection. The provided composition already applies the Clarity Card fragment to the collection display for rendering each item. To display article content from the collection, you’ll need to map the card’s sub-elements to fields in the articles. But before mapping the card’s sub-elements to content fields, let’s change the collection display’s pagination.

  14. For Pagination, select None.

    Now let’s map the card’s sub-elements to their corresponding fields in the articles.

  15. Select the Clarity Card fragment and note the sub-elements included:

    • card-image
    • category
    • card-title
    • summary
    • card-link
  16. Select each of the following elements, set its Source Selection to Mapping, and select the corresponding field:

    • card-image: Image under Content (Article)
    • category: Articles under Categorization
    • card-title: Title under Basic Information
    • summary: Headline under Content (Article)
  17. Select the card-link sub-element, go to the Link tab.

  18. For Link, select Mapped URL.

  19. For Field, select Default.

  20. Click Publish to save your changes to the Home page.

    The Helpful Articles section of the Home page should now display web content from the collection you created. However, two elements aren’t working as expected: category and card-link. This is because the articles do not have categories assigned to them and because the articles do not have a default display page template. Let’s fix these issues.

  21. Go to the Web Content application and assign one category to each article.

  22. Go to the Page Templates application, go to the Display Page Templates tab, and set the Article display page template as the default for its type.

  23. Return to the Home page and verify all mappings work.

Go to the Home page and check if all mapped fields work.

Great! You created a manual collection and displayed it in Clarity’s Home page. Next, you’ll learn how to create a dynamic collection.

Exercise 13b: Creating a Dynamic Collection

Having categorized your FAQ web content articles earlier, here you’ll use those categories to build dynamic FAQ collections as Walter Douglas.

To do this,

  1. Open the Site Menu (Site Menu), expand Site Builder, and select Collections.

  2. Click New and select Dynamic Collection.

  3. For Title, enter FAQ - Retail Partners a nd click Save.

  4. For Item Type, select Web Content Article.

  5. For Item Subtype, select FAQ.

    This limits the collection to FAQ web content articles. Next, you’ll define the collection’s scope and filter to limit which FAQs are included in the collection.

  6. Under Scope, click Select and select Other Site or Asset Library.

  7. Go to the Asset Libraries tab and click Marketing Assets.

    This ensures the collection uses FAQ articles from the Marketing Assets library.

  8. Under Filter, set the rule to Contains *All* of the following Categories.

  9. In the Categories field, search for Retail Partners and select it.

    Set a rule to only include FAQ items with the Retail Partners category.

  10. Click Save to create the collection.

  11. Repeat the above steps to create these collections:

    • FAQ - Products & Services
    • FAQ - Pricing & Ordering
    • FAQ - Returns & Exchanges

    Create an FAQ collection for each category.

    For each collection, filter results using its corresponding category.

You now have four FAQ collections. Next, you’ll use them to display content in Clarity’s FAQ page.

Exercise 13c: Displaying Content on the FAQ Page

Using what you have learned in the previous exercises, let’s map content to the FAQ page as Walter Douglas.

To do this,

  1. Begin editing the FAQ page.

  2. Double click the Image fragment to configure its image-square sub-element.

  3. Set the image to glasses-vertical-banner-with-text-lg from the Marketing Assets library.

  4. The block on the right contains a page title and four FAQ Section compositions. Each FAQ Section contains a heading and a Collection Display fragment. Each Collection Display contains a custom fragment called FAQ Question and Answer Pair. First map the collection displays to the FAQ collections you built earlier. Make sure each collection corresponds to the heading for that section.

    Map each collection display according to its heading.

  5. For Pagination, select None.

  6. Check Display All Collection Items.

  7. Map the correct fields for each FAQ Question and Answer Pair so that the content renders properly in the collection displays.

  8. In the Promoted Articles container, map the collection display to the Helpful Articles collection.

  9. Configure this setting for the FAQ Content and Promoted Articles containers:

    TabSettingValue
    GeneralContainer WidthFixed Width
  10. Click Publish to save your changes to the FAQ page.

Publish the changes and check the finalized FAQ page.

Using collection displays and custom fragments, you have rendered FAQ web content onto Clarity’s FAQ page. Next, let’s add content to the header announcement bar.

Exercise 13d: Adding Announcements to the Header

Here you’ll apply what you’ve learned about web content, collections, and page templates to add an announcement to Clarity’s header bar as Walter Douglas.

To do this,

  1. Open the Site Menu (Site Menu), expand Site Builder, and select Collections.

  2. Create a new dynamic collection titled Announcements.

  3. In the collection configuration menu, set Item Type to Web Content Article and Item Subtype to Announcements.

  4. For scope, select the Marketing Assets library.

  5. Click Save to publish the collection.

    Now that you’ve created the collection, let’s add it to the Primary Master Page template.

  6. Open the Site Menu (Site Menu), expand Design, and select Page Templates.

  7. Begin editing the Primary Master Page template.

    Note: You may notice the styles applied to the master page are different from those applied in site pages. This is because you’ve applied the theme and theme CSS client extension to site pages and not to master pages. If desired, you can apply the theme and client extension to the master page directly. Make sure you uncheck all theme properties (e.g., Show Footer, Show Header, etc.).

  8. Toggle the visibility (Visibility) of the Header Announcement Bar container.

  9. Select the Header Announcement Bar container and configure this setting:

    TabFieldValue
    StylesBackground > ColorColor Brand Primary

    Set the container's background color to Color Brand Primary from the style book.

    Note: Color options are defined by the theme’s style book. Unless you’ve applies the theme CSS client extension to the master page template, the Color Brand Primary option appears purple. This value is overridden in site pages by the Theme CSS client extension.

  10. Add a Collection Display fragment to the container, select it, and configure these settings:

    TabFieldValue
    GeneralCollectionAnnouncements
    GeneralPaginationNone
    GeneralMaximum Number of Items to Display1
  11. Add a Container fragment to the collection display, rename it Announcement, and configure these settings:

    TabFieldValue
    GeneralContent DisplayFlex Row
    GeneralAlign ItemsCenter
    GeneralJustify ContentCenter
  12. Add a Paragraph fragment to the container, select it, and configure these settings:

    TabFieldValue
    StylesText > ColorColor Neutral 0

    Set the paragraphs's text color to Color Neutral 0 from the style book.

  13. Select the paragraph’s element-text sub-element and configure this setting:

    TabFieldValue
    MappingFieldMessage
  14. Add a Clarity Button fragment to the Announcement container after the paragraph, select it, and configure these settings:

    TabFieldValue
    GeneralTypeBorderless
    GeneralStylePrimary
    GeneralSizeSmall
    GeneralInvertedYes
  15. Select the button’s link sub-element and configure these settings:

    TabFieldValue
    MappingFieldLink Text
    LinkLinkMapped URL
    LinkFieldLink to Page
  16. Adjust the margins and padding for the announcement bar elements until you are satisfied with it.

    Make the final adjustments to the announcement bar.

  17. Click Publish Master to save your changes.

The Header Announcement Bar is now visible on all pages that use the Primary Master Page template. Next, let’s use Liferay’s Commerce features to create Clarity’s products catalog.

Exercise 14a: Creating Clarity’s Products Catalog

A catalog is a group of related products. Liferay catalogs provide a highly flexible way to organize your product offerings in the most sensible way for your business.

Here you’ll create a catalog for Clarity’s products as Ian Miller.

To do this,

  1. Sign in as Ian Miller.

    • Username: ian.miller@clarityvisionsolutions.com
    • Password: learn
  2. Open the Global Menu (Global Menu), go to the Commerce tab, and click Catalogs.

  3. Click Add (Add Button).

  4. Enter the following:

    FieldValue
    NameClarity Eyewear
    Default Catalog LanguageEnglish (United States)
    CurrencyUS Dollar

    Create a catalog to group related products together.

  5. Click Submit to finish creating the catalog.

The catalog should appear in the Catalogs section after saving.

Great! Now that you’ve created the catalog, you can start adding products to it. But first, let’s add specifications that you can add to Clarity’s products when you create them.

Exercise 14b: Defining Product Specifications

Product specifications store information about products, like size, material, and color. To improve organization, you can also save them into specification groups.

Here you’ll add product specifications as Ian Miller.

To do this,

  1. Open the Global Menu (Global Menu), go to the Commerce tab, and click Specifications.

  2. Click the Specification Groups tab.

  3. Click New to add a new specification group.

  4. Enter the following:

    FieldValue
    TitleFrame Description
    Priority10.0
    Keyframe-description
  5. Click Save to finish creating your product specification group.

    You can now add product specifications to it.

  6. Return to the Specification Groups overview and go to the Specification Labels tab.

  7. Click New to add a new specification.

  8. Enter the following:

    FieldValue
    LabelFrame Material
    DescriptionThe material of the frame.
    Use in Faceted NavigationYes
    Default Specification GroupFrame Description
    Keyframe-material
  9. Click Save to finish creating your specification label.

  10. Create two more specifications with these values:

    • Frame Color

      FieldValue
      LabelFrame Color
      DescriptionThe color of the frame.
      Use in Faceted NavigationYes
      Default Specification GroupFrame Description
      Keyframe-color
    • Frame Size

      FieldValue
      LabelFrame Size
      DescriptionThe size of the frame (in default units).
      Use in Faceted NavigationNo
      Default Specification GroupFrame Description
      Keyframe-size
  11. Return to the Specification Labels page.

Create three Product specification labels.

Now that you’ve added some specifications, you can apply them to products as you create them.

Exercise 14c: Creating Products

Products represent the items sold by a company. Like any manufacturer, Clarity has a wide variety of products designed to achieve different goals and target different customer profiles.

Here you’ll add products to Clarity’s catalog, apply specifications and more as Ian Miller.

To do this,

  1. Open the Global Menu (Global Menu), go to the Commerce tab, and click Products.

  2. Click Add (Add Button) and select Simple.

    Note: A simple product is any physical product for which inventory is tracked.

  3. Enter the following:

    FieldValue
    NameClassic Aviator Sunglasses
    CatalogClarity Eyewear
  4. Click Submit to finish creating your product.

    Now you can configure the product. First, add a product description using ChatGPT.

  5. In the Full Description field editor, click on the AI Creator button (AI Creator Button).

  6. Enter a description, tone, and word count.

    For example,

    FieldValue
    DescriptionA product description for a pair of classic aviator sunglasses made for sunny days.
    ToneFriendly
    Word Count200
  7. Click Create. This generates your content.

  8. Click Add to copy the response into the Full Description field.

    Alternatively, click Try Again to generate a new response.

    Now that you’ve added a long description, let’s categorize the product.

  9. In the Categorization section, click Select for Clarity Products.

  10. Select Sunglasses and click Done to apply the category to this item.

    Now that the product is categorized, add some specifications.

  11. Scroll down and type Frame in the Add Specifications field.

    This lists available specifications.

  12. Select Frame Material, Frame Color, and Frame Size specifications, and close the modal window.

  13. In the Specifications section, click Frame Material to begin editing it.

  14. Enter the following:

    FieldValue
    ValueMetal
    Position10
  15. Click Save.

  16. Repeat steps 7-9 for the other specifications and enter these values:

    • Frame Color:

      FieldValue
      ValueGold
      Position20
    • Frame Size:

      FieldValue
      Value54-20
      Position30

    Now that your product has specifications, let’s add an image for the product.

  17. Click Save as Draft to save your changes.

  18. Go to the Media tab.

  19. For Images, click Add (Add Button) and click Select File.

  20. Select the classic-aviator-sunglasses image from the Product Images asset library.

  21. Enter these details for the image:

    FieldValue
    TitleClassic Aviator Sunglasses
    Priority10.0
  22. Click Publish to save the product image.

    Add the image to the product's media.

  23. Click Publish to finish creating the product.

  24. Repeat the above steps to create two more products: AquaComfort Plus Dailies and Single Vision Lenses. Tags should be typed directly into the Tags field in the Details screen.

    ProductSpecificationsCategoriesTagsImage
    AquaComfort Plus DailiesN/AContactsdailyaquacomfort-plus-dailies
    Single Vision LensesN/ALensesdailybiofinity-toric-lenses

    Note: To add the tag, type daily into the Tags field.

    Create three Products.

Great! Now that you’ve added products, you can set up a channel to display them in Clarity’s site.

Exercise 14d: Creating a Commerce Channel

Channels determine the storefront where products are displayed and sold to customers.

Here you’ll create a channel and link it to Clarity’s public enterprise website as Ian Miller.

To do this,

  1. Open the Global Menu (Global Menu), go to the Commerce tab, and click Channels.

  2. Click Add (Add Button).

  3. Enter the following:

    FieldValue
    NameClarity Public
    CurrencyUS Dollar
    TypeSite
  4. Click Add to finish creating your channel.

    Note: To display products in a site, you must link it to a channel.

  5. Go to the Type tab and click Select Site.

  6. Choose Clarity Public Enterprise Website.

  7. Click Save.

Create the Clarity Public commerce channel.

With the channel created, let’s return to Clarity’s site and finish setting up their product pages.

Exercise 14e: Setting Up the Product Pages

The training workspace includes three pages for displaying Clarity’s products: Products, Product List, and Product Details. Each page is already wireframed.

Here you’ll finish setting up each page as Walter Douglas.

Updating the Products Page

The Products page is a marketing page intended to showcase the product categories defined in the Clarity Products vocabulary. By selecting a category, users are directed to the Product List page where they’ll only see products from the selected category.

To implement this,

  1. Sign in as Walter Douglas.

    • Email: walter.douglas@clarityvisionsolutions.com
    • Password: learn
  2. Go to the Products page and begin editing it (Edit Button).

  3. Open the Fragments and Widgets panel (Fragments and Widgets).

  4. Go to the Widgets tab.

  5. Drag and drop the Commerce Categories Navigation widget into the Commerce Categories container.

  6. Hover over the widget, click the Actions button (Actions Button) in the top right corner of the widget, and select Configuration.

  7. For Vocabulary, select Clarity Products.

    Note: Do not enable the Use Root Category option.

  8. Click Save and close the modal window.

    The Clarity Products categories should appear after saving.

  9. Click Publish to view the updated page.

    Currently, you have a list of categories, but this is a long way from Clarity’s designs. The content of this widget is dynamically updated, so it’s easier to maintain as new categories are added and old categories are updated or retired. Now let’s do something about the design.

  10. Open the Site Menu (Site Menu), expand Design, and select Templates.

  11. Go to the Widget Templates tab.

  12. Click New and select Commerce Categories Navigation Template.

  13. Enter Clarity Category Cards as the template name.

  14. From the training workspace, go to the [repository-folder]/exercises/lesson-14/ folder and open the commerce-category-navigation-cards.ftl file.

  15. Copy and paste the contents of this file into the editor.

  16. Click Save.

  17. Return to the Products page and begin editing it (Edit Button).

  18. Hover over the Commerce Categories Navigation widget, click the Actions button (Actions Button) in the top right corner of the widget, and select Configuration.

  19. For Display Template, select Clarity Category Cards.

  20. Click Save and close the window.

  21. Click Publish to view the page.

Use a display template for the Clarity Category Cards widget.

Great! You can see we are a lot closer to the final design requested by Clarity. Now that you’ve finished the Products page, let’s complete the Product List page.

Creating the Product Listing Page (PLP)

As you’ve probably noticed, while the Commerce Categories Navigation widget looks better and provides us links to each category, the links aren’t working. That’s because Liferay doesn’t know which page to display for each category. For Liferay to recognize a page as a category display page, we can either assign it in the Channel settings or add the Category Content widget to it.

Currently, the Product List page includes most of the necessary widgets to display lists of products, but it’s not connected to Liferay’s category display feature.

To fix this,

  1. Go to the Product List page.

  2. Click Edit (Edit Button) to begin editing the page.

  3. From the Fragments and Widgets panel (Fragments and Widgets), drag and drop the Category Content widget just above the Search Results container.

  4. Click Publish.

  5. Return to the Products page and click one of the category cards to confirm it is working properly.

    The Category Navigation should be working. However, the Search Results widget is blank, as it has no display template set to it. To fix that, let’s create a new template for that widget.

  6. Open the Site Menu (Site Menu), expand Design, and select Templates.

  7. Go to the Widget Templates tab.

  8. Click New and select Search Results Template.

    Important: There are two “Search Results Template” options. One is for general search results while the other one is for Commerce products. Try selecting the second option first. If it’s the right one, you will see some commerce specific variables in the Elements menu (i.e., Commerce Product Search Result Display Context and Commerce Product Catalog Entries). If you do not see these variables, try using the other template.

  9. Enter Clarity Search Results Cards as the template name.

  10. From the training workspace, go to the [repository-folder]/exercises/lesson-14/ folder and open the commerce-search-results-cards.ftl file.

  11. Copy and paste the contents of this file into the editor.

  12. Click Save.

  13. Go to the Product List page and begin editing it (Edit Button).

  14. Hover over the Search Results widget, click Actions (Actions Button) in the top right corner of the widget, and select Configuration.

    Note: The Search Results widget should look blank, towards the bottom right side of the layout.

    The Search Results widget should look blank.

  15. For Render Selection, select Use Application Display Template.

  16. For Display Template, select Clarity Search Results Cards.

    Note: If you don’t see the template here, return to step 8 and try the other Search Results template.

  17. Click Save and close the window.

  18. Click Publish.

  19. Return to the Products page and click one of the category cards to confirm it is working properly and you are seeing your new template.

    The Search Results widget should now display the products.

Creating the Product Display Page

Finally, when you click a product in the Product List page, it doesn’t work as expected. This is because Liferay doesn’t know which page to use to display product details.

To fix this,

  1. In the Page Templates application, go to the Display Page Templates tab, and click New.

  2. Select Primary Master Page.

  3. Enter these values and click Save:

    FieldValue
    NameProduct Details
    Content TypeProduct

    This creates a new display page template for products.

  4. Drag and drop the Product Details Page fragment composition into the drop area.

    Drag and drop the Product Details Page fragment composition into the drop area.

  5. In the Product Details container, map these fragments with their corresponding product fields.

    FragmentFragment Sub-ElementMapping
    Product Nameelement-textName (Basic Information)
    SKUelement-textSKU (Basic Information)
    Descriptionelement-htmlDescription (Basic Information)
  6. Select the button’s link sub-element and configure these settings:

    TabFieldValue
    LinkLinkPage
    LinkPageContact Us
  7. Double click the Button fragment and change its text to Contact Sales.

  8. In the Specifications container, double click the Heading fragment and change its text to Specifications.

  9. Map fragments in the Specifications container to their fields:

    FragmentFragment Sub-ElementMapping
    Specification Nameelement-textName (Basic Information)
    Specification Valueelement-textValue (Basic Information)
  10. In the Attachments container, double click the Heading fragment and change its text to Attachments.

  11. Map fragments in the Attachments container to their fields:

    FragmentFragment Sub-ElementMapping
    Attachment Nameelement-textTitle (Basic Information)
  12. Select the Download button and configure these settings in the configuration side panel:

    TabFieldValue
    GeneralStyleLink
    GeneralSizeSmall
  13. Select the Download button’s link sub-element and configure these settings:

    TabFieldValue
    LinkLinkMapped URL
    LinkFieldDownload URL
  14. Double click the Download button and change its text to Download.

  15. Click Publish.

  16. Click Actions (Actions Button) for the Product Details template and select Mark as Default.

  17. Return to the Category Display page and select one of the products to confirm it is working.

Congratulations! You’ve set up Clarity’s product pages. Next you’ll explore how to use Liferay’s headless APIs.

Exercise 15a: Connecting to Headless APIs using the API Explorer

Let’s see how headless APIs can be used by interacting with it through Liferay’s API Explorer. Here you’ll add a new blog post as Walter Douglas.

To do this,

  1. Open the Site Menu (Site Menu), expand Configuration, and select Site Settings.

  2. Select Site Configuration under Platform.

  3. Copy down the Site ID and save it for a future step.

  4. Open the Site Menu (Site Menu), expand Categorization, and select Categories.

  5. Click Blog Posts under the Clarity vocabularies.

  6. Select one of the categories in the list.

  7. In your browser’s navigation bar, copy down the category’s ID that appears in the page URL. For example, (...)categories_admin/vocabulary/37819/category/[category-id]. You’ll use this ID in a later step.

  8. Open a new browser window and access Liferay’s API Explorer at http://localhost:8080/o/api.

  9. Scroll down to the Document section and expand the postSiteDocument endpoint.

    Tip: To quickly find the endpoint, search the browser page for postSiteDocument.

    You can see all endpoints related to a section.

  10. For the siteId field, enter the site ID for Clarity Public Enterprise Website.

  11. For the document field, delete the default JSON content and uncheck Send empty value.

  12. For file field, click Choose File and select glasses-book.png from the [repository-folder]/exercises/lesson-15/ folder.

  13. Click Execute.

    This uploads a new image file to Clarity’s Documents and Media.

  14. In the response body, look for the image’s ID. For example:

    (...)
    "fileExtension" : "png",
    "fileName" : "glasses-book.png",
    "id" : [image-id],
    "keywords" : [ ],
    (...)
    

    Copy down the image ID to use in the next step.

  15. Scroll up to the BlogPosting section and expand the postSiteBlogPosting endpoint.

  16. For siteId, enter the site ID for Clarity Public Enterprise Website.

  17. For Request Body, delete the default JSON content.

  18. From the training workspace, open the blog-entry.json file in the [repository-folder]/exercises/lesson-15/ folder.

    This file contains a blog post entry with a custom headline and body content.

  19. Copy the contents of blog-entry.json into the Request Body field.

  20. Replace {image-id} and {category-id} with your image ID and the blog category ID, respectively.

  21. Click Execute. Make sure the response code is 200.

  22. Return to the Clarity Public Enterprise Website window, open the Site Menu (Site Menu), expand Content & Data, and click Blogs.

  23. Confirm the Things I Find Interesting in Eyewear blog post appears.

    Use Headless APIs to add a blog post.

Exercise 15b: Using Headless APIs to Batch Import Web Content

Clarity wants to import three legacy web articles from their old portal into their new enterprise website. Here you’ll add them using Liferay’s Headless APIs as Walter Douglas.

To do this,

  1. Return to the browser window for Liferay’s API Explorer (http://localhost:8080/o/api).

  2. Scroll down to the StructuredContent section and expand the postSiteStructuredContentBatch endpoint.

  3. For siteId, enter the site ID for Clarity Public Enterprise Website.

  4. For Request Body, delete the default JSON content.

  5. From the training workspace, open the import-web-content-articles-batch.json file in the [repository-folder]/exercises/lesson-15/ folder.

  6. Copy the contents of import-web-content-articles-batch.json into the Request Body field.

  7. Click Execute.

  8. Return to the Clarity Public Enterprise Website window, open the Site Menu (Site Menu), expand Content & Data, and click Web Content.

  9. Open the Articles folder and confirm all three articles appear.

    The three web content articles should appear in the folder.

Exercise 15c: Using Headless APIs to Batch Import Products

You can use REST APIs to import Clarity’s products from external systems to Liferay DXP, streamlining product management. Here you’ll use APIs to create products as Ian Miller.

To do this,

  1. Sign in as Ian Miller.

    • Username: ian.miller@clarityvisionsolutions.com
    • Password: learn
  2. Open the Global Menu (Global Menu), go to the Commerce tab, and click Products.

    Take note of the number of existing products (i.e. 3).

  3. Open the Global Menu (Global Menu), go to the Commerce tab, and click Catalogs.

  4. Click Clarity Eyewear.

    Copy down the catalog’s ID. You’ll use it in a later step.

  5. Open a new browser window and access Liferay’s API Explorer at http://localhost:8080/o/api.

  6. Click the REST Applications drop-down menu and select headless-commerce-admin-catalog/v1.0.

  7. Scroll down to the Product section and expand the postProductBatch endpoint.

  8. For Request Body, delete the default JSON content.

  9. From the training workspace, open the import-products-batch.json file in the [repository-folder]/exercises/lesson-15/ folder.

  10. Copy the contents of import-products-batch.json into the Request Body field and replace {catalog-id} for all products with the Clarity Eyewear catalog ID.

  11. Click Execute.

  12. Return to the Clarity Public Enterprise Website window, open the Global Menu (Global Menu), go to the Commerce tab, and click Products.

  13. Confirm eight new products appear.

    Eight new products should appear.

Exercise 15d: Using Headless to Import Taxonomy Categories

As a multinational company, Clarity has many business locations around the globe. To better support recruitment efforts, Clarity needs to define categories that they can apply to job openings for each office location. Some categories already exist, but others are still missing.

Here you’ll add the missing location categories as Clarity Admin.

To do this,

  1. Sign in as the Clarity Admin user.

    • Username: admin@clarityvisionsolutions.com
    • Password: learn
  2. Open the Global Menu (Global Menu), go to the Applications tab, and click Asset Libraries.

  3. Select the HR library and click Categories.

  4. Go to the Location vocabulary in the left side menu.

    Take note of the number of existing location categories (i.e. 14).

  5. In your browser’s navigation bar, copy down the vocabulary’s ID that appears in the page URL. For example, (...)categories_admin/vocabulary/[vocabulary-id]. You’ll use this ID in a later step.

  6. Open a new browser window and access Liferay’s API Explorer at http://localhost:8080/o/api.

  7. Click the REST Applications drop-down menu and select headless-admin-taxonomy/v1.0.

  8. Scroll down to the TaxonomyCategory section and expand the postTaxonomyVocabularyTaxonomyCategoryBatch endpoint.

  9. For taxonomyVocabularyId, enter the vocabulary ID for Location.

  10. For Request Body, delete the default JSON content.

  11. From the training workspace, open the import-taxonomy-categories-batch.json file in the [repository-folder]/exercises/lesson-15/ folder.

  12. Copy the contents of import-taxonomy-categories-batch.json into the Request Body field.

    You can post content to a vocabulary using its ID.

  13. Click Execute.

  14. Return to the HR Asset Library window and refresh the page.

    The new locations should appear.

  15. Click HR in the breadcrumb menu to return to the library overview page.

  16. Click Web Content and open the Job Listings folder.

  17. Begin editing an article and assign any of the newly added locations (e.g. Morocco, Casablanca).

  18. Click Publish. You can now search for the content using the new location category.

Exercise 16a: Configuring Publications and Workflow for Content

You can leverage Publications with Workflow to implement robust publishing processes for site and content changes. Here you’ll enable publications and configure a single approver workflow for any new articles published to Clarity’s website as Ian Miller.

To do this,

  1. Sign in as Ian Miller.

    • Username: ian.miller@clarityvisionsolutions.com
    • Password: learn
  2. Open the Global Menu (Global Menu), go to the Applications tab, and click Publications.

  3. Toggle Enable Publications and click Save.

    This redirects to the Publications application page.

  4. Click Add (Add Button) to create a new publication.

    Alternatively, you can click the Publications drop-down menu at the top of the page and select Create New Publication.

  5. For Name, enter Article Publication.

  6. Click Create.

  7. Return to Clarity Public Enterprise Website.

  8. Open the Site Menu (Site Menu), expand Content & Data, and click Web Content.

  9. In the Web Content tab, click Actions (Actions Button) for the Articles folder and select Edit.

  10. Expand the Structure Restrictions and Workflow section and select Set the default workflow for the folder’s content (Articles).

  11. Select Single Approver in the drop-down menu.

  12. Click Save.

    The Single Approver workflow will be assigned to the Articles folder.

You have set up a publication for tracking changes to Clarity’s article web content, along with a workflow for approving new articles before they are published to the production site.

Next, let’s learn how to invite other users to work on the publication you created.

Inviting Users and Assigning Roles in a Publication

The Publications application has an option to invite users to collaborate in a publication. These users can be invited even if they don’t have Publications permissions assigned to them.

Here you’ll invite Christian Carter and Clara Murphy to contribute to the Article Publication process as Ian Miller.

To do this,

  1. Go to the Publications application click Actions (Actions Button) for Article Publication and select Invite Users.

    Alternatively, you can click the Publications drop-down menu at the top of the page, select Review Changes, and click Invite Users (Invite Users Button).

  2. Click the role drop-down menu and select Editor.

  3. For People, enter Christian Carter.

  4. Repeat steps 3-4 to invite Clara Murphy using these values:

    NameRole
    Clara MurphyPublisher

    Invite Christian Carter and Clara Murphy to the Article Publication.

  5. Click Send and click OK to confirm.

Great! Now Christian Carter and Clara Murphy can contribute to the publication. Next, you’ll go through the publishing workflow.

Exercise 16b: Managing Changes with a Content Publishing Workflow

Publications provides a convenient way to manage changes to your Liferay instance. With it, you and your team can create and collaborate on blocks of changes called ‘publications’. You can then publish those changes to production when ready.

In this exercise you’ll add a new article as Christian Carter, then review it with the single approver workflow and push the changes to production as Clara Murphy. These changes will be done in the Article Publication process.

Creating and Submitting a New Article to the Workflow

Here you’ll create a new article and submit it for approval as Christian Carter.

To do this,

  1. Sign in as Christian Carter.

    • Username: christian.carter@clarityvisionsolutions.com
    • Password: learn

    Note that the publications menu now appears at the top of the page and a new notification for the publication invitation was received.

    The publications menu appears and a new notification was received.

  2. Click the user profile icon, go to Notifications, and select the publications invitation.

    The invitation notification appears in the notification queue.

    This opens the details page for Article Publication.

  3. Click the Publications drop-down menu at the top of the page, click Select a Publication, and select Article Publication.

  4. Return to Clarity Public Enterprise Website, open the Site Menu (Site Menu), expand Content & Data, and click Web Content.

  5. Go to the Articles folder, click New, and select Article.

  6. Enter these values:

    FieldValue
    TitleClarity x Warby Parker
    Imagerevolutionizing_industry (from the Marketing Assets library)
    HeadlineSummer 2024 Collaboration
    ContentEyewear enthusiasts rejoice! Fan favorites Clarity and Warby Parker have joined forces for a collaborative collection.
  7. Click Submit for Workflow.

Great! You just created a new article and submitted it for review in the Article Publication. Next, you’ll learn how to approve and publish changes.

Reviewing Content in a Workflow and Publishing a Publication

Here you’ll finish reviewing the article and pushing all changes to production as Clara Murphy, Christian Carter’s manager.

To do this,

  1. Sign in as Clara Murphy.

    • Username: clara.murphy@clarityvisionsolutions.com
    • Password: learn

    The publications menu now appears at the top of the page and two new notifications for the publication invitation and review request were received.

    The invitation and review request notifications appear in the menu.

  2. Click the Publications drop-down menu at the top of the page, click Select a Publication, and choose Article Publication.

  3. Click the Publications drop-down menu again and select Review Changes.

    This directs to the publication details page with a list of changes.

  4. Click Publish.

    This action will fail because the publication includes unapproved changes.

    The action will fail if any changes are pending.

  5. Click the user profile icon and go to My Workflow Tasks.

  6. Go to the Assigned to My Roles tab to see the pending workflow task.

  7. Click Actions (Actions Button) for the workflow task and select Assign to Me.

  8. Enter a comment and click Done.

    This assigns the task to Clara Murphy and redirects you to the Assigned to Me tab. Here she can review and approve or reject the Christian Carter’s article.

  9. Click Actions (Actions Button) for the task and select Approve.

  10. Enter a comment and click Done.

  11. Click the Publications drop-down menu again and select Review Changes.

    The change’s status is now Approved.

  12. Click Publish, verify there are no conflicts, and click Publish again to add the changes to production.

    You can publish the publication if there are no conflicts.

Great! You’ve successfully used workflow with publications to review and publish a web content article. Next, you’ll learn how to leverage Liferay’s Search capabilities to improve user experience.

Exercise 17a: Adding Search Capabilities to the Job Listings Page

As part of improving their recruitment efforts, Clarity wants to implement a search page for open positions. Currently, Clarity’s website includes a wireframed page for this purpose, but it is missing the necessary search widgets to make it functional.

Here you’ll add and configure these widgets as Walter Douglas.

To do this,

  1. Sign in as Walter Douglas.

    • Email: walter.douglas@clarityvisionsolutions.com
    • Password: learn
  2. Open the Site Menu (Site Menu), click Page Tree, expand Careers, and click Open Positions

  3. Click Edit (Edit Button).

  4. Open the Fragments and Widgets panel (Fragments and Widgets).

  5. Go to the Widgets tab.

  6. Drag and drop a Search Bar widget into the Banner container, placing it under the Heading fragment.

  7. Select the widget and configure this setting:

    TabSettingValue
    General > FrameMin Width500px

    Next, you’ll add widgets for displaying and filtering search results, as well as defining additional search options.

  8. From the Fragments and Widgets panel, drag and drop a Type Facet widget into the grid’s left dropzone.

  9. Hover over the widget, click Actions (Actions Button) in the top right corner of the widget, and select Configuration.

  10. Use the right arrow button (Right Arrow Button) to remove all asset types except for Web Content Article.

    Configure the asset type to only include web content articles.

    This ensures that only web content articles appear in search results.

  11. Click Save and close the configuration window.

  12. From the Fragments and Widgets panel, drag and drop three Category Facet widgets into the left dropzone of the grid fragment, under the type facet widget.

  13. Hover over the first Category Facet widget, click the Actions button (Actions Button) in the top right corner of the widget, and select Configuration.

  14. For Display Template, select the Clarity Search Category template.

    You can select a display template for the category facet.

  15. For Category Parameter Name, enter a unique value (e.g., category-region).

    Note: Each Category Facet widget must have a unique parameter name to function as expected.

  16. Scroll down and choose Select Vocabularies.

  17. Expand the Clarity Enterprise Website vocabularies and select the Region vocabulary.

    The widget will only show the categories from the Region vocabulary.

  18. Click Save and close the configuration window.

  19. Repeat steps 12-17 for the other category facet widgets, though select different vocabularies for each one:

    • For the second widget, select the Location vocabulary.

    • For the third widget, select the Job Positions vocabulary.

  20. From the Fragments and Widgets panel, drag and drop a Search Results widget into the right dropzone of the grid fragment.

    Important: Ensure you’re using the widget from the Search widget section. Do not use the Commerce Search Results widget.

  21. From the Fragments and Widgets panel, drag and drop a Search Options widget below the grid fragment in the Search Results and Options container.

  22. Hover over the Search Options widget, click Actions (Actions Button) in the top right corner of the widget, and select Configuration.

  23. Check Allow Empty Searches.

  24. Click Save and close the window.

  25. Click Publish.

    You can now search for open job positions.

    Finally, let’s update the Explore Open Positions button in the Careers page to link to the Open Positions page.

  26. Go to the Careers page and begin editing it (Edit Button).

  27. Double click the banner’s Explore Open Positions button to open the configuration side panel for the button’s link element.

  28. In the configuration side panel, go to the Link tab and configure these settings:

    SettingValue
    LinkPage
    PageOpen Positions
  29. Click Publish.

Now that you’ve added search functionality to Clarity’s open positions page, site visitors can search and filter openings by different categories. You’ll revisit this page in a later exercise to further restrict which web content articles appear in the search results.

Next, you’ll apply these search concepts to Clarity’s product pages.

Exercise 17b: Adding Search Capabilities to Product Pages

Here you’ll take a closer look at the product list page to understand the different Liferay search widgets and how to configure them as Walter Douglas.

To do this,

  1. Go to Clarity’s Product List page. Most of the page is already built with different search widgets.

    The product list page is made up of different widgets.

    The left side module is made up of a search bar widget, a specification facet widget, and an option facet widget. The right side module is made up of a sort widget and a search results widget. Note that the search results widget under the commerce category of widgets is different from the search results widget under the search category of widgets. Only the commerce-related widget returns products.

    Below these two modules, there is a search options widget. If you inspect the configuration of this widget, you will see that Allow Empty Searches is enabled. This setting is enabled so that all available assets are shown without any search queries.

  2. Click Edit (Edit Button) in the Application Bar.

    The page is still missing a category facet widget that would allow visitors to filter by the different types of Clarity products. Let’s go ahead and add that widget.

  3. From the Fragments and Widgets panel, drag and drop a Category Facet widget below the Search Bar in the left dropzone of the grid fragment.

  4. Hover over the new Category Facet widget, click the Actions button (Actions Button) in the top right corner of the widget, and select Configuration.

  5. For Display Template, select the Clarity Search Category template.

  6. Click Save and close the configuration window.

  7. Click Publish.

    Use the category facet widget to filter by product category.

Great! You’ve included a category facet widget on the Product List page, allowing customers to filter their search results by product category.

Next, let’s finish configuring the Open Positions page to only display Job Listings in the search results.

Exercise 17c: Filtering Results with Custom Filters

So far you’ve seen how to filter search results by content type (e.g. blogs, web content, etc.), categories, and specifications. You can also apply custom filters using almost any indexed attribute in your content, such as a web content structure.

In a previous exercise, we limited the search results on the Open Positions page to only display Web Content Articles. However, search results still includes types articles that are not job listings.

Here you’ll use custom filters to search results to job listings as Clarity Admin.

To do this,

  1. Sign in as the Clarity Admin user.

    • Username: admin@clarityvisionsolutions.com
    • Password: learn
  2. Open the Global Menu (Global Menu), go to the Applications tab, and click Asset Libraries.

  3. Select the HR library and click Web Content

  4. Go to the Structures tab and copy down the structure’s ID.

    You’ll use this with the Custom Filter widget to limit search results in the Open Positions page.

  5. Go to the Open Positions page and click Edit (Edit Button).

  6. From the Fragments and Widgets panel, drag and drop a Custom Filter widget below the grid fragment in the Search Results and Options container.

  7. Hover over the Custom Filter widget, click Actions (Actions Button) in the top right corner of the widget, and select Configuration.

  8. For Filter Field, enter these values:

    SettingValue
    Filter FieldclassTypeId
    Filter ValueThe Structure’s ID
    InvisibleYes
  9. Click Save and close the window.

  10. Click Publish.

    Only job listings should appear in the Search Results.

    The Custom Filter widget limits search results to job listings.

Great! You’ve set a custom filter widget that limits the search results to only display Job Listings web content in the Open Positions page.

Next, you’ll learn how to use Search Blueprints as another method for customizing search results.

Exercise 18a: Customizing Search Results with Search Blueprints

Here you’ll revisit the Open Positions results page and create a Search Blueprint to only return recent job listing articles as the Clarity Admin user.

To do this,

  1. Sign in as the Clarity Admin user.

    • Username: admin@clarityvisionsolutions.com
    • Password: learn
  2. Open the Global Menu (Global Menu), go to the Applications tab, and click Asset Libraries.

  3. Select the HR library and click Web Content.

  4. Go to the Structures tab and begin editing Job Listing.

  5. Click Properties (Properties) and copy down the Structure Key value.

  6. Open the Global Menu (Global Menu), go to the Applications tab, and click Blueprints.

  7. Click Add (Add Button).

  8. For Title, enter Job Listings Last 60 Days.

  9. Click Create.

  10. In the right side menu, search for Filter by Exact Terms Match and click Add to include it in your query.

  11. For Field, enter ddmStructureKey.

  12. For Values, enter the Job Listing Structure Key.

    Add the filter by exact terms match element to the search blueprint.

  13. In the left navigation, click Query Settings.

  14. Click Selected Types and click Select Asset Types.

  15. Select Web Content Article and click Done.

  16. In the top menu, click Preview and enter a job listing search (e.g., Developer).

  17. In the left navigation, click Query Elements.

  18. Click Add (Add Button) to add another query element above the first one.

  19. In the right side menu, search for Custom JSON Element and click Add for the element.

  20. Delete the Custom JSON Element’s sample JSON.

  21. From the training workspace, open the filter-last-60d.json file in the [repository-folder]/exercises/lesson-18/ folder.

  22. Copy the contents of filter-last-60d.json into the Custom JSON Element.

    Copy the provided JSON into the Custom JSON Element.

  23. Click Preview and click Refresh to see the filter applied.

  24. In the Custom JSON Element, change "now-60d" to "now-1d" and click Refresh in the search preview to see the filter applied.

  25. Change the value back to "now-60d".

  26. Click Save.

    Next, you’ll update the Open Positions page to use the search blueprint.

  27. Go to the Open Positions page and click Edit (Edit Button).

  28. From the Fragments and Widgets panel, drag and drop a Blueprints Options widget below the Search Options widget in the Search Results and Options container.

  29. Click the Actions menu (Actions) and select Configuration.

  30. For Blueprint, click Select and select the Job Listings Last 60 Days blueprint.

  31. Click Save and close the window.

    With the blueprint applied, you can now remove the Type Facet and Custom Filter widgets from the page.

  32. Click Publish.

    Now the search results only include job listings created in the last 60 days.

Great! You’ve created a search blueprint and applied it to the Open Positions page as an alternative to the Type Facet and Custom Filter widgets.

Next, you’ll learn how to use search blueprints with collection providers.

Exercise 18b: Dynamic Collections with Search Blueprints

One simple way to leverage search blueprints is with collection providers. Every time you create a search blueprint, a collection provider is automatically generated. Then, showing the results of the search blueprint is as easy as adding a collection display fragment to site pages.

For example, Clarity wants to have a site page that automatically displays a list of upcoming events. A search blueprint can query upcoming events on their calendar to automatically fetch these upcoming events.

Here you’ll implement this as Clarity Admin.

Creating a Calendar Page

  1. Open the Site Menu (Site Menu), expand Site Builder, and click Pages.

  2. Click New and select Page.

  3. Select Primary Master Page.

  4. For Name, enter Calendar.

  5. Click Add.

  6. In the Fragments and Widgets side panel, go to the Widgets tab.

  7. Drag and drop the Calendar widget into the page.

  8. Click Publish.

    Now that you’ve created the page, add some events to the calendar.

  9. In the list of site pages, click Actions (Actions button) for the Calendar page and select View.

  10. Select the Month view and click any date before your current date, enter Past Event 1 as the name, and click Save.

  11. Click any date that is after your current date, enter Future Event 1 as the name, and click Save.

  12. Add one more event after Future Event 1 that is named Future Event 2.

    The calendar has one past event and two future events.

With the page and events set up, you can set up a search blueprint. But before you do that, enable the feature flag for the blueprint integration with collections element for future events.

Enabling the Blueprint and Collections Integration

  1. Open the Global Menu (Global Menu), go to the Control Panel tab, and click Instance Settings.

  2. Click Feature Flags and go to the Beta tab

  3. Enable Collections with Search Blueprints (LPS-129412).

    Important: Beta features should not be used in production environments.

With this feature enabled, you can create a search blueprint element for future calendar events.

Creating a Future Events Search Blueprint Element

  1. Open the Global Menu (Global Menu), go to the Applications, and click Blueprints.

  2. Go to the Elements tab and click Add.

  3. For Title, enter Future Events

  4. Click Create.

  5. Delete the default JSON content.

  6. From the training workspace, open the filter-future-events.json file in the [repository-folder]/exercises/lesson-18/ folder.

  7. Copy the contents of filter-future-events.json into the JSON field.

  8. Click Save.

Now you can create a blueprint that uses this element to query future events.

Creating a Future Events Search Blueprint

  1. While in the Blueprints application, go to the Blueprints tab.

  2. Click Add (Add Button).

  3. For Title, enter Future Events

  4. Click Create.

  5. In the right side menu, search for Future Events and click Add to include it in your query.

  6. In the left navigation, click Query Settings.

  7. Click Selected Types and click Select Asset Types.

    Change the asset type to calendar event.

  8. Select Calendar Event.

  9. Click Done.

  10. Click Save.

With the blueprint defined, you can now use its collection provider in a site page to render future events.

Using the Blueprint Collection Provider

  1. Go to the Calendar page.

  2. From the Fragments and Widgets panel, drag and drop a Container fragment above the below the Calendar widget.

  3. Select the container and configure these settings in the configuration side panel:

    TabSettingValue
    GeneralContent DisplayFlex Column
    GeneralAlign ItemsCenter
    GeneralJustify ContentCenter
    StylesSpacing > PaddingSpacer 6 (top and bottom)
  4. From the Fragments and Widgets panel, drag and drop a Heading fragment into the container.

  5. Set the Heading fragment’s text to Upcoming Events.

  6. From the Fragments and Widgets panel, drag and drop a Collection Display fragment into the container below the Heading.

  7. Select the Collection Display.

  8. In the configuration side panel, click Select Collection (Select Collection).

  9. Go to the Collection Providers tab and select Future Events.

  10. Configure these settings:

    TabSettingValue
    GeneralStyle DisplayBulleted List
    GeneralPaginationNone
  11. Click Publish.

    The collection display shows the future events.

    The search blueprint automatically provides a collection of future events that’s rendered by the collection display.

You’ve now created and configured a search blueprint that uses a collection provider to display future calendar events.

Next, you’ll learn how to leverage search blueprints with custom fields, then query those fields using headless APIs.

Exercise 18c: Search Blueprints with Custom Fields

Occasionally businesses need to integrate with other web services. For example, Clarity wants their employee benefits system to reference their employees based on the service’s registration ID numbers. In Liferay, you can add custom fields to user accounts for this value. Then you can use Liferay’s headless APIs to query the custom field.

User Account APIs cannot filter for custom fields directly, but you can use search blueprints for this purpose. Here you’ll implement this as Clarity Admin.

To do this,

  1. Open the Global Menu (Global Menu), go to the Control Panel tab, and click Custom Fields.

  2. Select User and click New.

  3. Select Input Field and enter these details.

    FieldValue
    Field NameRegistrationId
    Data TypeInteger
  4. Click Save.

  5. Open the Global Menu (Global Menu), go to the Control Panel tab, and click Users & Organizations.

  6. Select Ian Miller, scroll down to the bottom, and enter 555777 for the registration ID.

  7. Click Save.

  8. Open the Global Menu (Global Menu), go to the Applications tab, and click Blueprints.

  9. Click Add (Add Button).

  10. For Title, enter Registration ID.

  11. Click Create.

  12. In the right side menu, search for Filter by Exact Terms Match and click Add to include it in your query.

  13. For Field, enter expando__keyword__custom_fields__RegistrationId_long.

  14. For Values, enter ${keywords}.

    Set the field and value for the query element.

  15. Click Save and copy down the blueprint’s ID.

  16. Open the Global Menu (Global Menu), go to the Control Panel tab, and click Instance Settings.

  17. Click Feature Flags and go to the Beta tab.

  18. Enable Search Headless API (LPS-179669).

    Important: Beta features should not be used in production environments, but this feature will be available as a full feature Q3 2024.

  19. Open a new browser window and access Liferay’s API Explorer at http://localhost:8080/o/api.

  20. Click the REST Applications drop-down menu and select portal-search-rest/v1.0.

  21. Expand the postSearchPage endpoint.

  22. For nestedFields, enter embedded.

  23. For search, enter 555777.

  24. For Request Body, delete the default JSON content.

  25. From the training workspace, open the api-post-search.json file in the [repository-folder]/exercises/lesson-18/ folder.

  26. Copy the contents of api-post-search.json into the Request Body field.

  27. Replace {blueprint ID} with your blueprint’s ID.

  28. Click Execute.

  29. Verify this returns Ian Miller’s user information.

    The API response returns Ian Miller's user account.

    This is one way you can use Liferay as a headless system that’s utilized by a third-party service.

You’ve used a custom registration ID field with search blueprints to retrieve user information.

Congratulations! You’ve completed all exercises for day two of Building Enterprise Websites.

Next, you’ll learn how you can use Liferay Objects to build business forms.

Capabilities

Product

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy