Skip to content
Browse files

update custom tags docs for parser change

  • Loading branch information...
1 parent 5c5495b commit 8d8a980666aa218f4476d51443a937fd800e34ac @paularmstrong committed Feb 27, 2012
Showing with 7 additions and 8 deletions.
  1. +7 −8 docs/custom-tags.md
View
15 docs/custom-tags.md
@@ -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;
@@ -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);
@@ -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 = [];
@@ -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));

0 comments on commit 8d8a980

Please sign in to comment.
Something went wrong with that request. Please try again.