Developing Standard Features Exercises (15.2.2)
Developing Standard Features Exercises (15.2.2)
Standard
Features
EXERCISES
EXERCISE 1. FILTER THE NEWS LIST
COMPONENT
On this exercise you will start by exploring the repository servlet.
Then, you will filter the news list using an Essentials extension point.
2 Use the lower part of the screen to navigate through the hierarchical
structure of the jcr.
You will notice that the presentation here is much simpler than in the
console.
At the top, you find four search options. We will now explore the SQL
search.
4 Append some different constraints and ordering to the query from step 3:
c. order by hippostdpubwf:lastModificationDate
d. asc or desc
5 Also check out the "Text" search option by entering a search term, e.g.
"lorem".
AHA!
━ Be aware that the queries will only retrieve data. Updating or deleting is
not possible with the repository servlet interface.
6 Log into the CMS. From the content perspective, browse to the “news”
folder.
Create one folder within “news” with the name of the current year i.e.
“2023”.
Create a second folder within the folder created previously with the
number of the current month i.e. “03”.
8 There you will find a script called “Add News Items”. On its repository path
property, use /content/documents/myproject/news/<year>/<month>
updating the year and the month respectively with the year and month
that you have in your project.
9 Execute the script and once it’s finished inspect the news folder and check
that the news items were created correctly.
10 In your source code navigate to the site/components module and find the
NewsComponent class. (hint: it’s in the org.example/components folder)
11 You’ll notice that we have some unused imports already available in this
class.
Make the class extend the unused import EssentialsNewsComponent and
add the following annotation to it:
@ParametersInfo(type = EssentialsNewsComponentInfo.class)
You probably noticed that the script you ran before added news items, some of
which have the word “Fake” in their title property. We are now going to remove
all those “Fake news” items, using a Filter.
12 Uncomment the contributeAndFilters method and add a new filter to the
filters list, for news that does not contain “Fake” in the title (You can use
“myproject:title” for the property to be filtered).
14 You may have a -preview structure that the Experience manager uses. If
that is the case, you must remove it now. Check if you have the node at the
path /hst:myproject/hst:configurations/myproject-preview and remove
it if it exists.
15 In the HST configuration, navigate to the workspace and find the main
container of the newslist
The News List component now uses the ParameterInfo class. We added a new
filter that we want to make available to the webmasters, so we will make a class
of our own.
5 Where you create the filter, retrieve the component parameters info.
Only create the filter if getFilterNews is true and getTextToFilter is not
empty.
8 Verify that the news component in the Experience manager has functional
new checkbox and input fields.
AHA!
━ You can localize your parameter name with a resource bundle. You can
read more about it:
https://xmdocumentation.bloomreach.com/library/concepts/template-
composer/annotate-channel-or-component-configuration.html
EXERCISE 3.
CONTRIBUTE TO THE MODEL
You might want to contribute to the Delivery API, customized for your own SPA
implementation. With the following exercise we will create an HST component
and add an additional JSON element to the Delivery API.
1 In your source code, navigate to the site/components module and find the
BannerComponent class that was added for you.
@ParametersInfo(type = EssentialsBannerComponentInfo.class)
public class BannerComponent extends EssentialsBannerComponent {
...
}
7 In the hst configuration, navigate to the workspace and find the main
container of the homepage.
EXERCISE 4.
CUSTOMIZE JSON BY REGISTERING A
MIXIN AND CONVERTER
In exercise 3, we added an additional (model) element to the Delivery API.
In this exercise, we will make more advanced changes to the Delivery API.
We will remove a redundant element and change the value of another element.
https://xmdocumentation.bloomreach.com/library/concepts/page-model-
api/customization.html
1 In your source code, navigate to the site module
(site/components/src/main/java).
@JsonIgnore
@Override
public String getComponentClass() {
return super.getComponentClass();
}
@JsonSerialize(/*converter = todo*/)
@Override
public String getName() {
return super.getName();
}
EXERCISE 5.
CREATE A DYNAMIC COMPONENT
In this exercise you are going to create a dynamic component based on the
example provided.
7 On the new document node, add a new child node called hst:fieldconfig of
type hst:jcrpath. This indicates that this new document parameter will
have a document picker for the users to choose the document from.
10 On the side panel choose the components tab, check if the new
component is there and add it to your homepage.
Let’s start by adding a new React component for the Dynamic Banner:
1 Open the frontend project located inside your archetype directory on root
level “/react”.
8 You might have noticed that the Content List React component was not
defined, so our Content page is not correct yet. We’re going to create a
React component similar to the News List component, to make it work.
10 Adjust its function name to be ContentList, and any other methods and
variables that you think are needed.
13 You should now have a working Content List component and detail page.
If it still doesn’t work, verify the mapping reference in App.tsx matches the
hst:label
(why? b/c this node is a hst:containeritemcomponent Primary type)
EXERCISE 7.
ADD THE ABOUT PAGE
For the About page we need a document and a sitemap item to make it available
on the site.
━ For an overview of all the available shortcuts in the Console use Ctrl-H.
We will reuse this document type for the About page, but it should not show up
in the content list.
1 In the CMS, go to the Content section and “Add new translated folder” in
the My Project folder. Name it service.
4 Use the View button from the document actions: note that there is no
preview available. It has no preview yet, because the document is not
matched by any sitemap item.
SITEMAP: You have now created a new URL /about in the sitemap.
CONTENT: the sitemap item points to the About Us document for content using
relativecontentpath.
STRUCTURE: the sitemap item uses the hst:pages/contentpage page template to
display it.
12 Click the “Done” button to close the menu editor and publish the changes
of the channel.
13 Verify in the site that the About menu item brings you to the /about URL in
the site.
Check if you can see that the About us document is rendered in full.
Can you explain what happened?
EXERCISE 8.
ADD A TWO COLUMNS PAGE
CONFIGURATION
You previously created the About Us page with a one column layout.
In this exercise, we will give the webmaster users the option to add additional
components on a new container on the right hand side of the page.
1 Go to the node
/hst:myproject/hst:configurations/myproject/hst:pages/contentpage
This node defines the content page template.
Using a property hst:referencecomponent, it inherits from the base
abstract page.
It has a child node, named “main” of primary type
hst:containercomponentreference.
We will use this main node as one of the two columns.
Right-click on the main node, and rename the main node “left”.
This is not a problem, we have just not created that container reference
yet.
4 The structure of the main part of the contentpage will change now.
Instead of just having one element main with no child components that
shows the content, we will have two nodes, left and right, to show content.
This drawing shows the change you are making.
Header
Footer
8 On the CMS, browse to the Experience Manager and check your changes.
What happened? Inspect App.tsx on your React application and try to
figure out.
9 As you probably noticed, our React app uses the path main to render our
main content area, but we just changed that. We need to adjust the react
code.
Add the following piece of code after the main BrComponent rendering:
<div className="row">
<div className="column">
<BrComponent path="left" />
</div>
<div className="column">
<BrComponent path="right" />
</div>
</div>
.column {
display: flex;
flex-direction: column;
flex: 1;
}
All rights reserved. No part of these pages, either text or image may be used for
any purpose other than its original intent.