You can render HTML stored or produced by a ViewModel column in a Turnkey page when you need administrator-authored or generated content to become part of the page markup.
What DataIsHtml does
Set the DataIsHtml tagged value on a column when the column value contains HTML markup that the browser should render rather than display as text.
For example, if a column contains:
<p>Welcome to <strong>our site</strong>.</p>
with DataIsHtml=True, the page shows a paragraph with our site in bold. Without it, the page shows the <p> and <strong> tags as text.
Use this for content such as:
- HTML written by an administrator in an HTML editor such as TinyMCE and stored in a Blob field.
- HTML generated by an expression, including an HTML report function such as
HtmlReport. - HTML that combines fixed markup with values from the current ViewModel.
Configure a column to render HTML
- Add a column to the ViewModel that returns the HTML string or Blob content you want to show.
- Set the column's
IsStaticproperty toTrue. - Add the tagged value
DataIsHtmlwith the valueTrue. - Use the column in the page as you would use a normal bound column.
The required configuration is:
| Setting | Value | Purpose |
|---|---|---|
IsStatic
|
True
|
Enables the column to be rendered as HTML. |
Tagged value DataIsHtml
|
True
|
Tells the client to treat the column value as HTML markup. |
For the rendering behavior and client implementation details, see Documentation:Render data as html.
Build HTML from data
A column expression can return an HTML string. For example, the following expression creates a table-cell div and appends the value of Attribute2:
'<div class="tk-data-table__cell NewStyle1">Halloj</div>'+self.Attribute2
Set DataIsHtml=True on that column so the returned string is rendered as markup. If you use model-defined styles, define the style in the model and reference its class name from the generated HTML.
Dynamic updates
The HTML value remains data-bound. When the column value changes dynamically, the rendered page content is updated dynamically as well. This lets you show content maintained by an administrator or generated from changing model data without treating it as fixed page markup.
Treat input as trusted HTML
DataIsHtml causes markup in the value to be used directly in the page. Only use it for HTML content you intend to render. In AngularJS-based rendering, HTML requires explicit trust handling because of browser security concerns; Documentation:Render data as html describes the required $sce and rawHtml handling.
Choose the right column behavior
| Need | Use |
|---|---|
| Render HTML markup contained in the column value | DataIsHtml=True
|
| Show a URL as a clickable external hyperlink | DataIsLink |
| Show an image from a URL rather than a database Blob image field | DataIsImageUrl |
Control the HTML input type for an editor
|
Column.Texttype |
See also
- Documentation:Render data as html
- Documentation:Showing data
- Documentation:Column.DataIsLink
- Documentation:Column.DataIsImageUrl
[[Category:Attributes and data types [Beginner]]]
