Search code examples
c1-cms

Use .cshtml pages in Composite C1 that aren't strict XHTML


I need to include some .cshtml / razor pages in a Composite C1 site that do not enforce strict XHTML / XML.

ie - any unclosed tags at the moment, for example, prevent the page loading.

A client requires this; is it possible?

Thanks


Solution

  • Wrap bad / unsafe markup in a CDATA section. Since the strict XML requirement is primarily needed inside the Composite C1 render engine and is typically not a concern for browsers, Composite C1 treat CDATA sections as "messy markup" which it will not parse, but just emit raw:

    <div>
      <![CDATA[
        Bad & ugly HTML!<br>
      ]]>
    </div>
    

    It will pass through Composite C1 unhindered and come out as:

    <div>
        Bad & ugly HTML!<br>
    </div>
    

    Above is quoted from http://docs.composite.net/Layout/Writing-XHTML

    Here is a simple example with Razor syntax:

    <div>
      <![CDATA[
        @{
          string unstructuredMarkup = "Bad & ugly HTML!<br>";
          @Html.Raw(unstructuredMarkup);
        }
      ]]>
    </div>