JavaScript in Layout Builder Tiles
Those with access can add JavaScript to individual Layout Builder tiles to make layouts and pages (Layout Control Files [LCFs]) more interactive. Layout Builder inserts JavaScript in the LCFs <head>
element in the order you set in the tile.
Add custom JavaScript that will run on any LCF page that uses this tile, as follows:
- When you create or edit a tile, select to see the Source editor for HTML, JavaScript, or a split view of both.
- The JavaScript editor shows you potential code errors.
- While in Split view, click the separator between the editors and drag to resize. To change your editor view, click the name for the view you want or close the view.
- To see how the tile will look when published, go to the page actions toolbar, click Preview.
- JavaScript tiles will also preview in layouts and LCF pages.
- Save and Launch.
- Then, add your tile to layouts to create LCF pages.
- If you have edited and re-launched a tile, update the layout(s) that use the tile. Edits will appear automatically in pages on the staging server that use the tile.
JavaScript ReferenceLink to this section
You can also add JavaScript references to use shared libraries and frameworks, like jQuery, in your tiles.
- When you create or edit a tile, go to Properties > JavaScript Reference.
- In the dropdown, select a preloaded reference.
- Or +Add > Create Reference.
- Enter name and internal or external URL.
- Select the checkbox to load this reference after the page loads.
- Click Create.
- Save and Launch.
As as many unique references as you like to as many tiles as you like. Don't add the same reference twice in a tile.
Manage References
Edit, delete, disable, and see where your JavaScript references are used (subscribers).
- Go to Content > Layout Builder > JavaScript References.
- Click the More Actions menu for a reference.
- Click Edit or File > View Subscribers, Disable, Delete.
View Subscribers
See the tiles that use the JavaScript reference. Click the tile name to preview the tile or Export to CSV.
Disable
Disable a JavaScript reference to prevent it from being added to new tiles. Tiles, layouts, and pages that use this reference will not be affected. Administrators will still have access to a disabled references and can enable it for use.
Delete
Delete a JavaScript reference to remove it from the list of available references. Administrators will no longer have access to a deleted reference. Deleted references will remain in existing tiles, layouts, and pages until you remove them.