Loading Audio...

Listen to Lesson
0:00
  • Speed 0.5x
  • Speed 0.75x
  • Speed 1x
  • Speed 1.25x
  • Speed 1.5x
  • Speed 2x
  • Brian
  • Caris

Updating Clarity's Theme

Themes serve as the foundation of Liferay site styling, including typography, color schemes, and more. Clarity wants to implement a unique digital experience for distributor pages. In this article, you'll achieve this by modifying their existing theme.

Exercise: Adding a Frontend Token Definition to Clarity's Theme

Here, you'll add a new frontend token to Clarity's theme CSS client extension and redeploy it to your instance.

  1. In your course workspace, navigate to the exercises/module-6/ folder.

  2. Move the frontend-token-definitions.json file to the client-extensions/clarity-theme/src/ folder.
    This file contains all the Dialect theme's frontend tokens. Since deploying frontend tokens overwrites existing tokens within the instance's current theme, you'll include the new token within this file.

  3. Go to the client-extensions/clarity-theme/src/ folder and open the frontend-token-definitions.json file with a text editor or IDE.

  4. Locate the second-to-last closing curly brace (}).

  5. Add a comma after the curly brace:

                [... additional fields omitted ...]
    			"label": "tabs",
    			"name": "tabs"
    		},
    	]
    }
  6. Insert a new line below the curly brace and add this code snippet:

    {
    	"frontendTokenSets": [
    		{
    			"frontendTokens": [
    				{
    					"defaultValue": "var(--color-neutral-5)",
    					"editorType": "ColorPicker",
    					"label": "Body Secondary Background",
    					"mappings": [
    						{
    							"type": "cssVariable",
    							"value": "body-secondary-background"
    						}
    					],
    					"name": "bodySecondaryBackground",
    					"type": "String"
    				}
    			],
    			"label": "body",
    			"name": "body"
    		}
    	],
    	"label": "Clarity Distributor Styles",
    	"name": "clarity-distributor-styles"
    }
  7. Ensure the code resembles this:

    			[... additional fields omitted ...]
    			"label": "tabs",
    			"name": "tabs"
    		},
    		{
    			"frontendTokenSets": [
    				{
    					"frontendTokens": [
    						{
    							"defaultValue": "var(--color-neutral-5)",
    							"editorType": "ColorPicker",
    							"label": "Body Secondary Background",
    							"mappings": [
    								{
    									"type": "cssVariable",
    									"value": "body-secondary-background"
    								}
    							],
    							"name": "bodySecondaryBackground",
    							"type": "String"
    						}
    					],
    					"label": "body",
    					"name": "body"
    				}
    			],
    			"label": "Clarity Distributor Styles",
    			"name": "clarity-distributor-styles"
    		}
    	]
    }
  8. Save the file.

  9. Within the client-extensions/clarity-theme/ folder, open the client-extension.yaml file with a text editor or IDE.

  10. Under the clarity-theme definition block, add this line below the clayURL property:

    frontendTokenDefinitionJSON: src/frontend-token-definition.json

    This property sets the location of the frontend token definitions for the client extension.

  11. Ensure the file resembles this:

    assemble:
        - from: build/buildTheme/img
          into: static/img
    clarity-theme:
        clayURL: css/clay.css
        frontendTokenDefinitionJSON: src/frontend-token-definition.json
        mainURL: css/main.css
        name: Clarity Theme CSS
        type: themeCSS
  12. Save the file.
    Now that you've implemented the new frontend tokens to the client extension, you can deploy it to your Liferay instance.

  13. Open a terminal and navigate to the client-extensions/clarity-theme/ folder in your course workspace.

  14. Run this command to build and deploy the client extension:

    blade gw clean deploy
  15. Verify it deploys successfully.

    2025-01-24 14:08:34.676 INFO [fileinstall-directory-watcher][BundleStartStopLogger:68] STARTED claritytheme_7.4.13 [1463]
    

    With the client extension deployed, you can now check the new frontend token.

  16. In your Liferay instance, open the Site Menu (Site Menu), expand Design, and click Style Books.

  17. Click New to start creating a new style book.

  18. For Name, enter Token Verification and click Save.

  19. In the right side bar's drop-down menu, select Clarity Distributor Styles.

  20. Verify that the Body Secondary Background token is present.

    Verify that the Body Secondary Background token is present.

    NOTE
    The Token Verification style book is for verification purposes only and won't be leveraged in the following exercises. Therefore, you can safely discard it. You'll explore style books in more detail in the next lesson.

Now Clarity can use the new token to modify their website's background color via style books.

Conclusion

With theme CSS client extensions, you can implement customized styling and frontend tokens for your theme. This simplifies customization and enhances your website's look and feel.

Next, you'll learn about how you can centralize style management with Liferay's style books.

loading-knowledge-label