Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0.0] Volt: Macro does not work! #12118

Closed
xerron opened this issue Aug 10, 2016 · 4 comments
Closed

[3.0.0] Volt: Macro does not work! #12118

xerron opened this issue Aug 10, 2016 · 4 comments
Labels
not a bug Reported issue is not a bug

Comments

@xerron
Copy link

xerron commented Aug 10, 2016

  • Phalcon Micro
  • View/Simple

service view:

use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
use Phalcon\Mvc\View\Simple as View;

$di->setShared('view', function () {    

 $config = $this->getConfig();
 $view = new View();
 $view->setViewsDir($config->application->viewsDir);
 $view->registerEngines([
        '.volt' => function ($view, $di) {
            $config = $this->getConfig();

            $volt = new VoltEngine($view, $di);

            $volt->setOptions([
                'compiledPath' => $config->application->cacheDir,
                'compileAlways' => $config->dev_environment,
                'stat' => $config->dev_environment,
                'compiledSeparator' => '_'
            ]);

            return $volt;
        },
        '.phtml' => 'Phalcon\Mvc\View\Engine\Php'
    ]);

return $view;

});

route micro:

$app->get('/', function () use ($app) {

    echo $app->view->render('system/index');

})->setName('home');

test volt: system/index.volt

<!doctype html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Welcome!</title>
</head>
<body>
{%- macro print_hello(hello) %}
    {{ hello }}
{%- endmacro %}
{% print_hello('hi! baby.') %}
</body>
</html>

result:

Syntax error, unexpected token IDENTIFIER(print_hello) in /home/xerron/Repo/php/u-w-u.com/app/views/sui/system/index.volt on line 11

#0 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->_compileSource('...', false)
#1 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->compileFile('/home/xerron/Re...', '/home/xerron/Re...', false)
#2 [internal function]: Phalcon\Mvc\View\Engine\Volt\Compiler->compile('/home/xerron/Re...')
#3 [internal function]: Phalcon\Mvc\View\Engine\Volt->render('/home/xerron/Re...', Array, true)
#4 [internal function]: Phalcon\Mvc\View\Simple->_internalRender('system/index', Array)
#5 /home/xerron/Repo/php/u-w-u.com/app/modules/system/app.php(20): Phalcon\Mvc\View\Simple->render('system/index')
#6 [internal function]: Closure->{closure}()
#7 /home/xerron/Repo/php/u-w-u.com/web/index.php(78): Phalcon\Mvc\Micro->handle()
#8 {main}
@sergeyklay sergeyklay added Need information need script to reproduce Script is required to reproduce the issue labels Aug 10, 2016
@andresgutierrez andresgutierrez changed the title [3.0.0] Volt: Macro not work! [3.0.0] Volt: Macro does not work! Aug 10, 2016
@andresgutierrez
Copy link
Contributor

andresgutierrez commented Aug 10, 2016

This statement is wrong:

{% print_hello('hi! baby.') %} 

If you want to call the macro you have to you use do:

{% do print_hello('hi! baby.') %} 

or

{{ print_hello('hi! baby.') }} 

https://docs.phalconphp.com/en/latest/reference/volt.html#expressions

@andresgutierrez andresgutierrez added not a bug Reported issue is not a bug and removed Need information need script to reproduce Script is required to reproduce the issue labels Aug 10, 2016
@xerron
Copy link
Author

xerron commented Aug 18, 2016

Yes bug!.
I am try.

{{ print_hello('hi! baby.') }} 

and notice:

Notice: Access to undefined property _macros in /home/xerron/Repo/php/u-w-u.com/var/cache/default/volt/_home_xerron_repo_php_u-w-u.com_app_views_sui_user_register.volt.php on line 43

@Jurigag
Copy link
Contributor

Jurigag commented Aug 18, 2016

I thought it was fixed - #11902 You sure you on 3.0.0 ?

@xerron
Copy link
Author

xerron commented Aug 19, 2016

Yes. Fix in branch 3.0.x. tank you. +1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not a bug Reported issue is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants