Loading...
Loading...
Loading...
Loading...
Loading...
Access Project Properties
Various properties from the current environment can be used within templates but access must be granted through the setProps
command in the hooks.js file first.
With this in place, we gain access to the following within template files.
{{project.siteURL}}
String
{{project.mode}}
String
{{project.title}}
String
{{project.slogan}}
String
{{project.copyright}}
String
{{project.email}}
String
{{project.contactText}}
String
{{project.enableSocialTags}}
Boolean
{{project.language}}
String
{{project.logo.url}}
String
{{project.logo.alt}}
String
{{page.title}}
String
{{page.description}}
String
{{page.id}}
String
{{page.language}}
String
{{page.filename}}
String
{{page.ext}}
String
{{page.absolutePath}}
String
{{page.docRootPath}}
String
{{page.resourcesPath}}
String
{{node.id}}
String
{{node.parent.id}}
String
{{node.parent.container}}
String
{{node.title}}
String
{{element.group}}
String
{{element.title}}
String
{{element.version}}
String
{{element.assetPath}}
String
{{element.siteAssetPath}}
String
Hooks provide a powerful way to extend your components by manipulating properties before they are applied within templates.
The typical flow of a component follows this sequence: properties → hooks → template. Hooks process and refine properties, allowing you to perform complex logic before passing them into the template for rendering.
Each component has its own unique hooks.js
file. To share code across multiple components, refer to shared hooks.
To use a transform hook, create a hooks.js
file in the root of your component with this code.
Next, add this to the template.html
file in the component templates directory.
rw:mode
string
edit
or preview
getValues
getClassNames
getResponsiveValues
getBreakpoints
getBreakpointNames
in hooks.js
in template.html
The rendered output would look something like this:
Mario - Plumber
The transform hook allows you to get and set property values before they're used in templates. Let's assume you have the following slider defined in your properties and you're using the value in a template.
When the slider is set to 5, the output would be
Now lets add a transform hook that multiplies the padding value by 2
With the slider still set to 5, when the template is processed the output will be
This becomes incredibly powerful and convenient when you need to perform logic based on multiple properties. The following example show how you might generate a list of css classes based on standard or custom settings.
The template simply uses the classes property instead of attempting to handle all options from 7 different properties. For example
The following template example will output the page (and folder) details for all the pages in a project.
Before you can access the page properties you'll need to include the following code in the Hooks.js