Skip to content
Auke edited this page Jul 2, 2014 · 2 revisions

This component provides a very basic templating ability, in two forms:

\arc\template::substitute

This method replaces '{$key}' entries in a string with the value of that key in an arguments list If the key isn't in the arguments array, it will remain in the returned string as-is. The arguments list may be an object or an array and the values may be basic types or callable. In the latter case, the key will be substituted with the return value of the callable. The callable is called with the key matched.

   $parsedTemplate = \arc\template::substitute( 
       'Hello {$world} {$foo}', 
       [ 'world' => 'World!' ] 
   );
   // => 'Hello World! {$foo}'

\arc\template::substituteAll

This method calls \arc\template::substitute and then removes and remaining unfilled keys and returns the result.

##\arc\template::compile

This method compiles a string which may contain php code to a callable function and returns it. It uses create_function, not eval, but you should use this with caution obviously.

##\arc\template::run

This method compiles the given template, if not done already, and calls the resulting function with the given arguments.

Clone this wiki locally