getherbert / herbert

The WordPress Plugin Framework:
http://getherbert.com/
632 stars 94 forks source link

Access the Helper class from Twig is not working #140

Open giwrgos88 opened 8 years ago

giwrgos88 commented 8 years ago

I want to use the helper into twing so i can load js and css files. So I did the following

in config file i have the following

    /**
     * The APIs to auto-load.
     */
    'apis' => [
        'APIHelper' => __DIR__ . '/app/api.php'
    ],

in the api.php I have the following

<?php 

namespace MyApp;

/** @var \Herbert\Framework\API $api */

/**
 * Gives you access to the Helper class from Twig
 * {{ MyPlugin.helper('assetUrl', 'icon.png') }}
 */
$api->add('helper', function ()
{
    $args = func_get_args();
    $method = array_shift($args);

    return forward_static_call_array(__NAMESPACE__ . '\\Helper::' . $method, $args);
});

and in the twig I'm doing the following but is null <script src="{{ APIHelper.helper('assetUrl', 'moment.min.js') }}" type="text/javascript" charset="utf-8" async defer></script>

does anyone know why?

giwrgos88 commented 8 years ago

any help?