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

function plugin return an array, modifier plugin is not falling. #228

Closed
rmasco opened this issue May 8, 2016 · 3 comments
Closed

function plugin return an array, modifier plugin is not falling. #228

rmasco opened this issue May 8, 2016 · 3 comments

Comments

@rmasco
Copy link

rmasco commented May 8, 2016

Always thank you , everyone .

One of the failure has occurred.
If example_function returns an array , the array is not falling into example_modifier.
smarty2, the array is falling into example_modifier.

template:

{{example_function name="list[0]"|example_modifier}

smarty3:

        ob_start();
        echo $_smarty_tpl->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['example_function'][0][0]->function_wrapper(array('name' => 'list[0]'), $_smarty_tpl);
        echo smarty_modifier_example_modifier(ob_get_clean(), 'test');

smarty2:

        echo smarty_modifier_example(smarty_example_function(array('name' => 'list[0]'), $_smarty_tpl);

example_modifier:

<?php

function smarty_modifier_example($text, $name) {
    var_dump($text);
}

example_modifier is return 'String[5] 'Array'.
How can I fix it ?

@uwetews
Copy link
Contributor

uwetews commented May 10, 2016

All tags including plugins should always return a string or nothing.
If it does return an array like in your case it could never work without a modifier allowing array as parameter. This requirement is not clear by the syntax.
Plugins with array or object results should assign it to a variable and then you can go from there.

I agree that the compiled code of Smarty 2 does create in your sense an expected result. I will look into it.

@rmasco
Copy link
Author

rmasco commented May 12, 2016

@uwetews
thanks!

I do assign to template variable be able to receive array in modifier.
This is the best way?

uwetews added a commit that referenced this issue Jul 18, 2016
@uwetews
Copy link
Contributor

uwetews commented Jul 18, 2016

Even that I think that normally plugins should return always strings I did fix the code to Smarty 2 behavior.
The fix is now in the master branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants