Is there any way to assign a var in a file and then get it working in other by including the first one?
I have front.tpl and front-topfeatures.tpl. In front-topfeaturs.tpl I want to assign a var like:
{{ assign var="featured_cond" value="`$featured_cond` number not `$gimme->article->number` " }}
and then use it in front.tpl.
You can set scope="global" in smarty but it does not work in Newscoop.
It doesn't work because variable scopes are available only in Smarty
3, in Newscoop we use Smarty 2. There is already a plan to start using
the version 3 but unfortunately it won't be ready for 3.6.0 as it
requires lots of testing time to make sure the template engine will
work ok after upgrading.
There must be some other way to do what you want, let's see if any of
our gurus in templating can help you out with this :-)
On Fri, Aug 26, 2011 at 6:57 PM, Tomasz Rondio
<newscoop-support@lists.sourcefabric.org[/email][/email]> wrote:
>
> Is there any way to assign a var in a file and then get it working in other by including the first one?
> I have front.tpl and front-topfeatures.tpl. In front-topfeaturs.tpl I want to assign a var like:
> {{ assign var="featured_cond" value="`$featured_cond` number not `$gimme->article->number` " }}
> and then use it in front.tpl.
> You can set scope="global" in smarty but it does not work in Newscoop.
>
It seems that it is impossible to do that in smarty 2.
Only way is to add this function to Smarty_Compiler.class.php
function _compile_include_tag($tag_args)
{
$attrs = $this->_parse_attrs($tag_args);
// ADD NEXT LINE (default value of the param scope = local).
$scope_action = "\$this->_tpl_vars =
array_merge(\$_smarty_tpl_vars,\$GLOBALS[\"_smarty_tpl_vars_temp\ "]);\n";
$arg_list = array();
if (empty($attrs['file'])) {
$this->_syntax_error("missing 'file' attribute in include tag",
E_USER_ERROR, __FILE__, __LINE__);
}
foreach ($attrs as $arg_name => $arg_value) {
if ($arg_name == 'file') {
$include_file = $arg_value;
continue;
} else if ($arg_name == 'assign') {
$assign_var = $arg_value;
continue;
}
if (is_bool($arg_value))
$arg_value = $arg_value ? 'true' : 'false';
// REPLACE THIS LINE WITH THE NEXT TWO
// $arg_list[] = "'$arg_name' => $arg_value";
if( $arg_name != 'scope' )
$arg_list[] = "'$arg_name' => $arg_value";
}
$output = '<?php ';
if (isset($assign_var)) {
$output .= "ob_start();\n";
}
As I said in my previous message, scope is only available in Smarty 3 :-)
So, this seems to work, but it's a patch to Smarty 2 basically, so I
would suggest something which is important: Take a look at how "scope"
works in Smarty 3, and if you decide to use this patch in Newscoop,
please make it work in the same way as "scope" in Smarty 3, because we
will soon switch from Smarty 2 to 3, and we wouldn't like to break
your templates in case you implement "scope" in a different way :-)
Good job,
All Best,
On Mon, Aug 29, 2011 at 10:03 AM, Micz Flor
<newscoop-support@lists.sourcefabric.org> wrote:
>
> nice one! this could also help to make templates easier to translate for multilingual publications - and using smarty variables for text on the page?
>
On Tue, Aug 30, 2011 at 10:26 AM, Tomasz Rondio
<newscoop-support@lists.sourcefabric.org> wrote:
>
> This patch works exacly like scopes in smarty 3. I didn't used it to be sure that template is compatible with any Newscoop installation.
>