@anchor
Create linkable anchors that appear in the Elements Link Panel
The @anchor directive creates a linkable anchor point within your component. Anchors defined with this directive automatically appear in the Elements Link Panel, making it easy for users to link to specific sections of your component from anywhere in their project.
Syntax
Using a literal string:
<div id="@anchor("anchorName")"></div>Using a property value:
<div id="@anchor(anchorProperty)"></div>How It Works
When you use @anchor, Elements:
Outputs the anchor name/value as the element's
idattributeRegisters the anchor in the Link Panel so users can select it when creating links
Enables smooth scrolling to the anchor when the link is clicked
Examples
Basic Anchor
Create a static anchor point:
This creates an anchor called "features" that users can link to via the Link Panel.
Dynamic Anchor from Property
Allow users to customize the anchor name through a component property:
Where sectionId is defined in your properties.json as a text input.
Multiple Anchors in One Component
Components can define multiple anchor points:
Accordion Sections
Create anchors for each accordion section:
Navigation Target
Create an anchor for a navigation section:
Anchors in Hooks File
For more complex anchor scenarios or when anchors need to be generated programmatically, you can use rw.addAnchor() in your hooks file instead of the template directive.
This is useful when:
Anchor names need to be computed from multiple properties
You need to conditionally add anchors based on complex logic
Anchors need to be added in a loop with dynamic IDs
See rw.addAnchor for more details on the hooks approach.
Best Practices
Use descriptive anchor names - Choose names that clearly describe the section:
"pricing","contact-form","testimonials".Keep anchor names URL-friendly - Use lowercase letters, numbers, and hyphens. Avoid spaces and special characters.
Consider user control - For reusable components, expose the anchor name as a property so users can customize it.
Document your anchors - If your component creates anchors, document them so users know what links are available.
Related
rw.addAnchor - Programmatic anchor creation in hooks file
Link UI Control - Creating link properties
Last updated
Was this helpful?

