Text template functions
std:text:paragraph(text)
This template function renders paragraph plain text. The string is split on newlines, and each paragraph is HTML escaped and enclosed in a <p>
tag.
std:text:document(document)
This template function renders XML document text as simple HTML, without widgets.
std:text:document:widgets(document)
This template function renders XML document text as HTML including widgets, requiring display within a standard layout to render properly.
std:text:list:readable(list style) { . }
Renders a list of values as text in a nicely human readable manner. The anonymous block is rendered for each value in list
with the context set to that value. If the block does not render anything, the associated item separator will not be rendered.
style
must be "en:default"
to render it in a default list style for the English language. For example,
std:text:list:readable(people "en:default") { . }
std:text:object-value(value)
Renders any JavaScript value, or a data object that can be stored as an attribute in a StoreObject
, as a simple text value.
In particular, if the value is a StoreObject
or a Ref
, the title of the object is rendered if the current user has permission to read it. This is particularly useful in cutting down the amount of code in a controller, because there is no need to conditionally load the object.
Example
Given a view with researcher
and supervisor
properties, each of which are a Ref
and the supervisor
is optional, this template renders a table.
<table> <tr> <th> "Researcher" </th> <td> std:text:object-value(researcher) </td> <tr> if(supervisor) { <tr> <th> "Supervisor" </th> <td> std:text:object-value(supervisor) </td> <tr> }
The code to generate the view is simple, as it does not need to load the objects to find their titles.
let object = O.ref(...).load(); let view = { researcher: object.first(A.Researcher), supervisor: object.first(A.Supervisor) // might be null }