Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

Parsing a page template with a custom function

edited June 2015 in Framework

I added my_function to apps/my_app/lib/Functions.php, but I can't figure out why my pages are blank when I use body|my_function in my default layout. If I add my_function to elefant's lib/Functions.php, it works fine. I also tried namespacing my_app's functions file and using body|my_namespace\my_function, but no luck there, either.

Even though the pages are blank I can't find any errors in the error log. Do I need to do something to register my app with elefant? So far, all I've done is ./elefant build-app my_app and then create apps/my_app/lib/Functions.php


  • PHP doesn't autoload functions. My recommendation is to create a Filter class and call it like this:

    namespace myapp;
    class Filter {
        public static function my_function ($input) {
            return strtoupper ($input);

    Then call it like this:

    {{ body|myapp\Filter::my_function }}

    That way it autoloads for you, and also gives you a place to keep filters together in one place.

  • I couldn't figure out why this wasn't working until I realized that the file needs to be called Filter.php and not, say, Functions.php.

  • Ah yes, that way the autoloader can find it. Glad it's working :)

Sign In or Register to comment.