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

Positional parameters ? #164

Closed
JulienPalard opened this issue Jan 15, 2016 · 1 comment
Closed

Positional parameters ? #164

JulienPalard opened this issue Jan 15, 2016 · 1 comment
Milestone

Comments

@JulienPalard
Copy link

I'm working on a {trans} block for Smarty, and I though it may be cool to accept positional parameters:

{trans "Jack" "dull boy"}All work and no play makes %s a %s.{/trans}

I imagine positional parameter to be given using integer keys in the $param parameter, nicely cohabiting with named parameter (strings key in the $param parameter).

But if it's not implemented, there's probably a good reason I miss ?

cdp1337 added a commit to cdp1337/smarty that referenced this issue May 3, 2016
This patch is what we've been using for some time for functions in Core Plus such as the date function, `{date $model.created}`.
It adds arguments assigned onto the parameter stack in the next index based on the order that they're set in.

This would fix smarty-php#164
@wisskid wisskid added this to the 5.0 milestone Jan 31, 2023
@wisskid
Copy link
Contributor

wisskid commented Jan 31, 2023

In v5.0 this will be possible by providing a custom TagCompiler.
For example:

class blockparamsCompiler extends \Smarty\Compile\Base {

	protected $shorttag_order = ["first", "second"];
	protected $optional_attributes = ["first", "second"];

	public function compile($args, Template $compiler, $parameter = [], $tag = null, $function = null) {
		$_attr = $this->getAttributes($compiler, $args);

		if (isset($_attr['first'])) {
			// ...
		}
                // ...

	}

}
$this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'testblock', blockparamsCompiler::class);
		$this->smarty->registerPlugin(Smarty::PLUGIN_COMPILER, 'testblockclose', blockparamsCompiler::class);

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

Successfully merging a pull request may close this issue.

2 participants