How to write module

donnerjack13589 edited this page Aug 31, 2010 · 6 revisions

nTPL is exposing internal variable modificators.

What is modificator?

When generating template from code like this:

{%your_modificator_name [arg] %}

nTPL will search for “your_modificator_name” modificator.
And then – use it!

How to declare modificator?

nTPL.modificators["your_modificator_name"] = function (arg, namespace, options) {
   /* some code here */


  • arg – equals to [arg].
  • Namespace – is an object that will be available in template (It will be the same in all your template instances)
  • options – is an object holding all current template options (they can be changed/added from your modificator or using {%set ... %} modificator, see Default modificators )

Modificator function

If nTPL matches modificator all code in modificator’s braces ( {% ... %} ) will be replaced with modificator’s functions return value.
So you can write code here and extend namespace:

function mod_func(arg, namespace,options) {
  return "$p('sometext', $_);";

This example can be simplified:
nTPL.modificators["mod"] = "$p('somtext', $_);";

For extending namespace see Filter module source or Block module source

Read more about nTPL’s API