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

Shorthand Syntax #1005

Open
SleepingForge opened this issue Apr 26, 2024 · 1 comment
Open

Shorthand Syntax #1005

SleepingForge opened this issue Apr 26, 2024 · 1 comment

Comments

@SleepingForge
Copy link

SleepingForge commented Apr 26, 2024

So in v5.0.0-rc3 I could register a Plugin-Function and do something like this:

{myFunc test1 arg='arg'}

because of this fix: #953 it's not possible anymore to assign string attributes, because of this section in Compiler/Base.php:

if (!is_array($mixed)) {
			// options flag ?
			if (isset($options[trim($mixed, '\'"')])) {
				$_indexed_attr[trim($mixed, '\'"')] = true;
				// shorthand attribute ?
			} elseif (isset($this->shorttag_order[$key])) {
				$_indexed_attr[$this->shorttag_order[$key]] = $mixed;
			} else {
				// too many shorthands
				$compiler->trigger_template_error('too many shorthand attributes', null, true);
			}
			// named attribute
		}

Because shorttag_order wasn't empty it would just insert Attribute test1 into $_indexed_attr and I could use it as ['var1'].
I found it quite useful cause the first argument could be used as some kind of identifier.

I found old issues that discuss this shorthand syntax for example: #165, #342, #568

So is this Syntax officially dead in Smarty v5.0.0? Or is there a way to kind of inject the first parameter still as a string?

Thank you!

@wisskid
Copy link
Contributor

wisskid commented Apr 29, 2024

The var1, var2, var3 shorttag order got into the release candidates for smarty 5 by accident. They didn't exist in Smarty v4 either.

We should be able to support this in a future version, but I think you should have a way to specify the number and names of the parameters. We might be able to extend FunctionHandlerInterface for this, which would allow you to write an Extension that supports shorthand attributes.

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