Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
update custom tags docs for parser change
Browse files Browse the repository at this point in the history
  • Loading branch information
paularmstrong committed Feb 28, 2012
1 parent 5c5495b commit 8d8a980
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions docs/custom-tags.md
Expand Up @@ -10,14 +10,13 @@ First, make sure to include your node.js file that declares your tags in the swi
Requirements <a name="requirements" href="#requirements">#</a>
------------

First, include the Swig parser and helpers.
First, include the helpers.

var parser = require('swig/lib/parser'),
helpers = require('swig/lib/helpers');
var helpers = require('swig/lib/helpers');

Define your tag and whether or not it requires an "end" tag:

exports.mytag = function (indent, parentBlock) {
exports.mytag = function (indent, parentBlock, parser) {
return 'output';
};
exports.mytag.ends = true;
Expand All @@ -27,15 +26,15 @@ A Really Simple Tag <a name="example" href="#example">#</a>

To parse a swig variable with or without filters into a variable token, eg. `bar` or `foo|lowercase`

exports.mytag = function (indent, parentBlock) {
exports.mytag = function (indent, parentBlock, parser) {
var myArg = parser.parseVariable(this.args[0]);
return 'output';
};
exports.mytag.ends = true;

Use a parsed variable token with `helpers.setVar()` to bind a variable in your current scope into the templates scope. The `setVar` method cleans up variable output, applies filters and escaping for clean output:

exports.mytag = function (indent, parentBlock) {
exports.mytag = function (indent, parentBlock, parser) {
var myArg = parser.parseVariable(this.args[0]),
output = '';
output += helpers.setVar(name, myArg);
Expand All @@ -45,7 +44,7 @@ Use a parsed variable token with `helpers.setVar()` to bind a variable in your c

To parse the inner content of a tag for outputting, use `parser.compile.apply(this, [indent, parentBlock])`:

exports.mytag = function (indent, parentBlock) {
exports.mytag = function (indent, parentBlock, parser) {
var myArg = parser.parseVariable(this.args[0]),
output = [];

Expand Down Expand Up @@ -87,7 +86,7 @@ To access a third-party library or method that is defined outside of your templa

Once you've added it, your custom tag can reference the `i18next` extension via the `_ext` object:

exports.trans = function (indent, parentBlock) {
exports.trans = function (indent, parentBlock, parser) {
var myArg = parser.parseVariable(this.args[0]),
output = [];
output.push(helpers.setVar('__myArg', myArg));
Expand Down

0 comments on commit 8d8a980

Please sign in to comment.