This article provides steps and samples on how to store and retrieve JavaScript for injection onto a template using Ektron content metadata.
Sometimes there is a need for scripts to be executed for specific content. It is recommended to not embed the script in the content HTML or executed in the XSLT for such content. Insertion of scripts in content or XSLTs can cause issues with rendering in the Workarea as well as on the template.
This is directly related to changes in Microsoft .NET defaults for script execution and Ektron's increase in security.
In these cases, it is recommended that Ektron metadata be used to accomplish this task.
Here is the documentation for Working with Metadata.
Here are the steps:
- Add a metadata configuration to the CMS system. In this sample, it is called "google js". Set the type as an HTML tag.
- Assign a default to this tag or assign the value at the content level. This value is the actual script code.
- If using a content block, pull the code and output to a page with code similar to below. The most important code is in the try statement.
- Output what is read to a literal or another control of choice.
Ektron.Cms.Controls.ContentBlock cb = CB; // ContentBlock ID on the ASPX page cb.DefaultContentID = ContentBlockId; try {// using the Ektron API I am pulling the metadata which is storing the js we want. Ektron.Cms.CustomAttributeList attlist = cb.GetMetaData(); Ektron.Cms.CustomAttribute metadata = attlist["google js"]; // Output the data to the literal in the MainView state. litGoogleDoubleClickJS.Text = Server.HtmlDecode(metadata.Value.ToString()); }
Here are some code samples:
For a sample Content Block widget and wireframe template to retrieve and inject script, click here.
For a sample ContentManager framework API to retrieve content metadata, click here.
Please sign in to leave a comment.