Scripted Pages
There are two kinds of pages that can contain EditMe's server-side JavaScript and attribute commands: Layouts and Scripted Pages.
Both Layouts and Scripted Pages are normal EditMe pages with a special MIME Type. The MIME Type of a page is set by clicking the Page Properties button at the bottom of the editing screen and selecting a MIME type from the list. Selecting one of these two options turns the page into a Layout or Scripted Page:
- EditMe Scripted Page (text/vnd.editme.xml-js.page) or EditMe Script (text/vnd.editme.js)
- EditMe Layout (text/vnd.editme.xml-js.layout)
See Layouts for a detailed discussion of what layouts are and how they are used in EditMe. Layouts and Scripted Pages are similar in several ways:
- EditMe forces both of these page types to be edited in Plain Text mode.
- Scripted Pages are EditMe pages that contain attribute commands and server-side server-side JavaScript and attribute commands.
- Like Layouts, Scripted Pages must be valid XML. This means they must have a single root XML node - a DIV or SPAN can be used for this. Scripted Pages execute when viewed by a user. Pages that have the MIME type EditMe Script (text/vnd.editme.js) are not XML validated. These pages contain only JavaScript code.
- Also like Layouts, Scripted Pages can be edited by Administrators only. Regardless of the access controls you set on a Scripted Page, non-Administrators will not be able to save the page. To avoid confusion, the security settings for Scripted pages should restrict editing to Administrators.
Scripted Pages are different from Layouts in that they must be viewed within the context of a Layout just like any other page. To include a scripted page in a Layout, you can use the process layout command. In this example, myscript is a variable containing the page object to be processed.
<div editme="process myscript" />
If you have a layout that contains a page that may or may not be scripted, you should check for the isScripted attribute and either use process or cdata accordingly. For example, the _Index and _Search pages are scripted, so all layouts include this code. Here is an example of this check:
<div id="content" editme="if !page.isScript ;; cdata page.content" /> <div id="content" editme="if page.isScript ;; process page" />
Finally, here is a sample scripted page that says Hello to the current user. Note that the content is valid XML, and note the use of an inline server-side script tag:
<span>
<script type="text/vnd.editme.js">
var username = user.name;
if (username=='') username='Anonymous User';
</script>
<p editme="parse">Hello, {username}!</p>
</span>