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

"too many shorthand attributes" error #568

Closed
TomPavelec opened this issue Jan 28, 2020 · 3 comments
Closed

"too many shorthand attributes" error #568

TomPavelec opened this issue Jan 28, 2020 · 3 comments
Labels
waiting Waiting for answer

Comments

@TomPavelec
Copy link

Current state

Good examples

When custom template function is called with named argument:

    {funcName arg=argumentValue}

in function body arg can be accessed:

    $arg = $params['arg'];

When more named arguments are passed:

 {funcName arg=argumentValue arg2=argumentValue2}

in function body args can be accessed:

    $arg1 = $params['arg'];
    $arg2 = $params['arg2'];

When more shorthand args are passed:

    {funcName argumentValue argumentValue2}

in function body args can be accessed:

    $arg1 = $params[0];
    $arg2 = $params[1];

Unexpected behavior (BUG)

But when one shorthand arg is passed:

    {funcName argumentValue}

The "too many shorthand attributes" error is triggerd.

Expected behavior

When one shorthand arg is passed (it should be the same as when more shorthand args are passed):

    {funcName argumentValue}

in function body arg can be accessed:

    $arg = $params[0];
@wisskid wisskid added the waiting Waiting for answer label Jan 28, 2020
@wisskid
Copy link
Contributor

wisskid commented Jan 28, 2020

did you use some for of custom compile stap to define shorttag attributes? The example you give creates an error for any number of shorthand attributes:

<?php
require_once './vendor/autoload.php';
$smarty = new Smarty();
$smarty->registerPlugin("function","funcName", function ($params, $smarty) { return ''; });
$smarty->display('string:{funcName argumentValue argumentValue2}');

returns

PHP Fatal error:  Uncaught  --> Smarty Compiler: Syntax error in template "string:{funcName argumentValue argumentValue2}"  on line 1 "{funcName argumentValue argumentValue2}" too many shorthand attributes <-- 
  thrown in /home/workspace/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php on line 1

@TomPavelec
Copy link
Author

Im sorry, it was caused by cached result (for case "When more shorthand args are passed").

But after this patch #569 is possible to use one/more shorthands in custom func call and then they are accessible by $params[0] in func body.

So its not a BUG, but i will appriciate that shorter func calls.

{func arg arg2 arg3}
instead of:
{func arg1=arg arg2=arg2 arg3=arg3}

@wisskid
Copy link
Contributor

wisskid commented Jan 29, 2020

Alright, i've renamed your PR to indicate this is not a bug but an enhancement, and referenced it in #165 where @cdp1337 suggested the same change. I'll close this issue now.

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

No branches or pull requests

2 participants