TemplateFunctionThis interface

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

Construction

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

Interface

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) {
    this.render(P.template("example-link").deferredRender({
        href: object.url(),
        title: this.deferredRenderBlock()
    }));
});

example-link is a template in the defining plugin:

<a href=href>
  render(title)
</a>

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

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

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".