Wednesday 30 September 2009 1:18:45 am
Hello Gaetano, Yes, passing vars down the chain is not an issue. Now, passing vars up the chain does not necessarily have to do anything in common with persistent variables. I mentioned those as that's part of my particular solution, but let's skip communication between node template and pagelayout template for a while. Let's concentrate on a node template only, here's an example:
{def $my_var=array()}
{attribute_view_gui attribute=$attribute in_attribute_var=$my_var}
{$my_var|attribute(show,1)}
and then in the attribute template included above:
...
{set $in_attribute_var=$in_attribute_var|append( 'new_element' )}
...
What does the inspection show you? Because it doesn't work down and up for me. Your last suggestion would be fine for pagelayout, it doesn't seem to work in node templates either. Maybe I did something wrong, but I naturally use global variables in the pagelayout included templates and those work fine. And I think it shouldn't even work since the module result templates are rendered before the pagelayout is (which is the fundamental thing for persistent vars to work...). Here's my solution, in form of three operators that do the trick about passing vars up and down in node templates - a bit primitive, but... ;)
case 'selfutils_php_globalvar_set':
{
$name = $namedParameters['name'];
$value = $namedParameters['value'];
global $selfUtilsPhpGlobalVar;
if ( !isset( $selfUtilsPhpGlobalVar ) )
{
$selfUtilsPhpGlobalVar = array();
}
$selfUtilsPhpGlobalVar[$name] = $value;
}
break;
case 'selfutils_php_globalvar_get':
{
global $selfUtilsPhpGlobalVar;
$name = $namedParameters['name'];
$result = null;
if ( isset( $selfUtilsPhpGlobalVar[$name] ) )
{
$result = $selfUtilsPhpGlobalVar[$name];
}
$operatorValue = $result;
}
break;
case 'selfutils_php_globalvar_append':
{
global $selfUtilsPhpGlobalVar;
$name = $namedParameters['name'];
$key = $namedParameters['key'];
$value = $namedParameters['value'];
if ( isset( $selfUtilsPhpGlobalVar[$name] ) )
{
if ( is_array( $selfUtilsPhpGlobalVar[$name] ) )
{
if ( $key === null )
{
$selfUtilsPhpGlobalVar[$name][] = $value;
}
else
{
$selfUtilsPhpGlobalVar[$name][$key] = $value;
}
}
}
}
break;
Cheers, Piotrek
--
Company: mediaSELF Sp. z o.o., http://www.mediaself.pl
eZ references: http://ez.no/partners/worldwide_partners/mediaself
eZ certified developer: http://ez.no/certification/verify/272585
eZ blog: http://ez.ryba.eu
|