KB Version:

Page Navigation

Related Links

Learning Levels

Most Read

Code Sections

Digest

Cascade Server currently supports the use of two types of code sections in the system-- Passthrough Code Sections, and Root Code Sections.

Concept

Passthrough Code Sections

Passthrough code sections instruct the interpreter to exclude the enclosed code when the page is being previewed internally. Upon publishing, the contents of these tags will be uncommented and included in the final page.

Passthrough-top Code Sections

The passthrough-top code section is used to support code that must be placed at the very beginning of a document (file or page) – for example, an ASP page that requires a processing instruction before the page's DOCTYPE. Because the system does not allow for XML comments before the root element or for DOCTYPE in a Template, such code must be placed inside of a passthrough-top code section.

Protect Code Sections

Protect code sections are meant to allow any content, including invalid XML, to be rendered both upon publishing and when rendering inside of Cascade Server. A common example of this is plain Javascript code where < and & characters would be otherwise illegal or unbalanced tags caused by a need for conditional comments such as <!--[if IE 7>.

Protect-top Code Sections

Protect-top code sections will be outputted above the rendered XML document both upon publishing and when rendering inside of Cascade Server. A common example of this is an unsupported doctype declaration or using Cascade Pages to dynamically render non-XML browser-supported code such as Javascript or CSS.

Skipping Code

It is possible to completely remove fragments of code both from rendering inside of Cascade Server and when publishing. It is also possible to remove portion of the rendering from given point to the end of that entire rendering.

Technical

Passthrough Code Section Tags

The  passthrough code section is delimited as follows: 

       

This deprecated way is also allowed:

        

When viewing a file or page containing these types of blocks within the CMS, these sections are left untouched unless the asset is a page with serialization type of PDF or RTF (as determined by the Target associated with the page's Template). If the serialization type is PDF or RTF the section is simply stripped from the code.

When publishing a file or page containing these blocks to a location outside the CMS, these sections are rewritten so that the enclosing comments and #passthrough strings are removed. However, when publishing a page with PDF or RTF serialization type, these sections are once again completely removed rather than rewritten.

For example, suppose we wanted to embed the following PHP code in a page:

          

Wrapping the passthrough code comment tags allows the page to validate as XML: 

           

When viewing this page in the system, this code would remain inside of the comments untouched; and the PHP code will not render (unless a PDF or RTF configuration of a page is viewed, in which case the comments and the code would be removed).

However, upon publishing to a file with serialization type of HTML or XML, the comment tags are stripped out leaving only the valid PHP code:

           

When publishing to a PDF or RTF file, or viewing a PDF or RTF configuration of the page within the system, the comments and the code would both be stripped out.

Passthrough-top Code Sections Tags

The second type of code section currently supported in the system is the passthrough-top code section, which is delimited as follows:

        

This deprecated way is also allowed:

         

The passthrough-top code section is used to support code that must be placed at the very beginning of a document (file or page) – for example, an ASP page that requires a processing instruction before the page's DOCTYPE. Because the system does not allow for XML comments before the root element or DOCTYPE in a Template, such code must be placed inside of a root code section.

The rules for rendering these code sections both inside and outside of the CMS are the same as for the passthrough code section with one notable difference - when publishing to a file or page with serialization type HTML or XML, the comment tags are removed, but the code inside the comments is actually moved to the beginning of the document. This can be useful if, for example, you need to include a page redirect at the top of the page, but you are using a template that does not have a content region defined at the very top.

For example, suppose you have the following .NET template:

Therefore, when a page using this template was published, the ASP instructions would appear before the page's DOCTYPE.

The following root code section tags could be used to create this template in the CMS:

If there were multiple passthrough-top code sections in a Page or File, they would be placed sequentially at the top of the document in the relative order that they appeared.

Protect Code Sections Tags

These code sections work the same as passthrough code sections with the exception that protect code sections are also rendered inside of Cascade Server. Because of that, the purpose of these code sections is shifted from outputting server side code to client side code such as Javascript. This also allows outputting unbalanced XML for old browser support.

Protect code sections are delimited as follows:
       

 


or

 


Using the CDATA format allows for special sequences of characters to be entered, such as -- which is commonly used in JavaScript as a decrement operation. During the last stage of rendering a Page, the special wrapping tags are stripped leaving the text ...put any code here... in the example above.

Below you will find an example that outputs unbalanced XML that could be used to aid the support of older web browsers.

 


This will result in following code which normally (without use of code sections) would not be allowed by Cascade Server:

 

Protect-top Code Sections Tags

These code sections work just as passthrough-top code sections but again with the exception that protect-top code sections are also rendered inside of Cascade Server. You can use these code sections to output a non-standard doctype, use Cascade Server Pages to dynamically render non XML content such as JavaScript, CSS or JSON, or output the HTML 5 Boilerplate code.

The syntax for client root code section is delimited as follows:
       
<!--#protect-top...put any code here...#protect-top-->


or

<![CDATA[#protect-top...put any code here ...#protect-top]]>

During the last stage of rendering the Page, the special syntax is stripped leaving the text ...put any code here... in the example above and that text is then being moved above the XML document.

The following code can be used to output the HTML 5 Boilerplate (h5bp) code:

 

The result of this code will be:

 

Cascade Skip Tags

In some situations it is useful to completely remove part of the code. This is possible through outputting #cascade-skip tag inside of HTML comments. For example, the code below:
    
<xml><!--#cascade-skip--><unnecessary-tag/><!--#cascade-skip--></xml>

will result with the <unnecessary-tag/> being removed after the page finishes rendering, right before it is published out or outputted to the screen:
<xml></xml>

Placing only one <!--#cascade-skip--> tag results with the remaining contents being fully stripped. This is especially useful together with the #protect-top tag. For example, this valid XML document:

 


will result with a pure JavaScript code completely stripped of XML tags:

 


A practical real life scenario would involve constructing an XSLT or Velocity format that dynamically renders contents inside of the protect-top code section in example above to get a result with dynamically generated JavaScript code.

Related Links