Allow to extend mustache #109

Open
jcubic opened this Issue Sep 13, 2012 · 0 comments

Comments

Projects
None yet
1 participant

jcubic commented Sep 13, 2012

Maybe it's good idea to allow extension of mustache wihout modifing library or Mustache class so user can put {{@foo}} or {{%foo}} and those will execute user defined function

$mustache = Mustache_Engine(array(
    'modifiers' => array(
       '%' => function($tag) {
            return file_get_contents($tag);
       }
    )
));

or

$mustache = Mustache_Engine(array(
    'tags_extension' => function($modifier, $tag_name, $leading, $trailing) {
        switch($modifier) {
            case '%':  return file_get_contents($tag_name);
        }         
    }
));

and user will be able to put

<html>
   <body>
      <h1>My robots.txt</h1>
      <pre>{{%robots.txt}}</pre>
   </body>
</html>

and those modifiers will be check in _renderTag method after all of tags or before so they can be overwriten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment