3

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

niico
  • 11,206
  • 23
  • 78
  • 161

2 Answers2

2

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>
mawtex
  • 436
  • 1
  • 4
  • 11
  • Thanks - how will this work with razor content - can that be inside the CDATA section? – niico Sep 11 '14 at 12:09
  • 1
    Yes, you can use all the features of Razor both outside and inside of the CDATA section. I've updated the answer so there is a simple Razor example also. – mawtex Sep 11 '14 at 14:17
2

You can set the ReturnType of your function to string (the default is XhtmlDocument). You do this by overriding the ReturnType property like this

@functions
{
   protected override Type FunctionReturnType
   {
      get { return typeof(string); }
   }
}
Pauli Østerø
  • 6,878
  • 2
  • 31
  • 48
  • Thanks - what are the relative advantages between this and the CDATA approach?! – niico Sep 15 '14 at 03:48
  • that you don't need to fiddle with CDATA, plus there are still some cases where CDATA won't cut it, ie. i never got a ´´ construct to work with CDATA. – Pauli Østerø Sep 15 '14 at 10:24