TemplateFunctionThis interface

An object used to render plugin defined template functions, passed as this when the implementing function is called.


TemplateFunctionThis object are automatically created by the templates rendering system. The objects may be reused for efficiency, but your implementation must make no assumptions.


property functionName

The name of the function being rendered.

function write(string)

Write the string, escaped for the current context.

function deferredRenderBlock(blockName)

Return a deferred render for the named block, or null for the anonymous block.

Where you’re using a template with render(), this allows you to include blocks from the template which uses your function.

For example, with this template function:

P.globalTemplateFunction("example:link-with-block-title", function(object) {
        href: object.url(),
        title: this.deferredRenderBlock()

example-link is a template in the defining plugin:

<a href=href>

And the function can be used in any other plugin like this:

  example:link-with-block-title(object) {
    <i> "Title: " </i>

function hasBlock(blockName)

Return true if the function has been called with a given named block, or null for the anonymous block.

function writeBlock(blockName)

Write the given named block, or null for the anonymous block.

function render(thing)

Render something. thing may be a deferred render or a template.

function unsafeWriteHTML(html)

Output the html without any escaping. Use with care.

function assertContext(context)

Assert that the function is being called in the right HTML context. context may be "TEXT" or "ATTRIBUTE_VALUE".