2012-02-02, 04:35:20
mvlcek Wrote:lbordas Wrote:Is it possible to pass a variable from a prevoius component, executed before in the same page, to a second component?
You can use global variables to pass values, e.g. with component1
and component2Code:<php
global $my_one1;
$my_one1 = ...
?>
but in the call {% component2 ... %} you can only place constant values as arguments.Code:<?php
global $my_one1;
if (isset($my_one1)) {
// do something with $my_one1
}
?>
(Make sure to have some prefix ($my_) for global variables in order to not come into conflict with GetSimple or plugins)
Hi mvlcek.
I need to pass the global variable name, so I used eval():
component1:
Code:
<?php
global $my_one;
$my_one = "Hi there";
?>
component2:
Code:
<?php
global $args;
echo eval('global $'. $args[0] . ';');
echo eval('return $'. $args[0] . ';');
?>
Then in the page I call:
{% test2 %}
{% test3 my_one %}
This way I can use the variable name as an argument in the second component (test3 in the example). I plan to use this to print different messages coming from a form validation, like errors...
Thanks a lot for your help :-)
Luis