Updating Clarity's Theme and Styling
Leveraging design elements to match your branding requirements is imperative for creating a robust business website. While Liferay provides out-of-the-box themes and style books to maintain styling consistency, extending those functionalities becomes necessary in some scenarios. Clarity wants to start a new sub-brand with unique visual identity called Clarity Kids. Clarity’s current theme uses a style book, and rather than starting from scratch for Clarity Kids, they want to use the theme CSS client extension to add new frontend tokens and update the typography.
Exercise: Updating Clarity’s Frontend Tokens
Here, you’ll add a new frontend token definition to Clarity’s current Theme CSS client extension. You’ll also import a new font family to override the current one.
-
Open a file explorer and navigate to the
/exercises/module-2/exercise-1
folder in your course workspace. -
Open the
frontend-token-definition.json
file and examine its contents. -
Move the
frontend-token-definition.json
file to the/client-extensions/clarity-theme/src/
folder in your course workspace. -
From the
clarity-theme
folder, open theclient-extension.yaml
file in a text editor or IDE. -
Add this line above the
name
property under theclarity-theme
definition block:For example.
-
Save the file.
-
From the
client-extensions/clarity-theme/src/css/dialect/variables/
folder, open the_color_scheme.scss
file and update the following variables by replacing their values with the following frontend token definition variables.This change maps the theme’s variables to the corresponding tokens in the
frontend-token-definitions.json
file. -
Save the file.
-
From the
client-extensions/clarity-theme/src/css/
folder, open the_imports.scss
file and append this snippet:This imports a font family from an external URL to override the current font.
-
Save the file.
-
Open a terminal and navigate to the
client-extensions/clarity-theme/
project folder in your course workspace. -
Run this command to build and deploy the client extension:
-
Verify it deploys successfully.
-
In your Liferay instance, sign in as the Clarity Admin user.
-
Username:
admin@clarityvisionsolutions.com
-
Password:
learn
-
-
Open the Site Menu (
), expand Design, and click Style Books. -
Select Clarity Kids Style Book to start editing it.
-
In the right side bar’s dropdown menu, select clarity-kids-components.
-
Verify that the following tokens are available.
-
Modify the colors using the available tokens and observe the real-time changes on your page.
-
Return to the Home page and confirm that it stays with the same style.
-
Confirm that the fonts were changed after you deployed the client extension.
Conclusion
Great! You’ve used the theme CSS client extension to add new frontend tokens to Clarity’s style book. The client extension approach enables you to create distinct visual identities for sub-brands quickly and efficiently. Next, you’ll learn more about implementing custom functionality with global JS client extensions.
Capabilities
Product
Education
Contact Us