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
Variable as a parameter in Smarty 5 #997
Comments
that seems wrong. I'll investigate. |
I have did some more analysis... Compiled .tpl file result (from cache): Seems like it's missing the |
Could you share the code of your implementation for |
Sure! So, I call it like this:
<?php
namespace SmartyExtensions;
use Smarty\Compile\Base;
class EmbedTag extends Base {
protected $required_attributes = ['type', 'url'];
protected $optional_attributes = ['cdn'];
public function compile($params, \Smarty\Compiler\Template $template, $parameter = array(), $tag = null, $function = null):string
{
$_attr = $this->getAttributes($template, $params);
if (!empty($_attr['type']) && !empty($_attr['url']))
{
$cdn_loc = '';
if (isset($_attr['cdn']))
$cdn_loc = $_attr['cdn'];
return \PageElement::embed(trim($_attr['type'], '\'"'), $cdn_loc.$_attr['url'], false, false);
}
}
} If you wonder why I trim the
|
Are you sure you want to compile your tag? Because then you cannot use any of the parameters the way you do, because they would no longer be dynamic. Maybe you want to write a FuncionHandler instead? |
Oh. I tried to follow the documentation but it seems I got it all wrong. |
Just have a look at |
Can we still pass the variable into the tag parameter in Smarty 5?
In the prior versions, I used it like this and it worked:
{embed type='JS' url='/js/categories.js' cdn=$CDN_URL}
Now, the "cdn" parameter, is equal to the string below instead of the $CDN_URL value:
"$_smarty_tpl->getValue('CDN_URL')"
The text was updated successfully, but these errors were encountered: