2011-06-08, 21:53:29
bugman Wrote:Now component is like an un parameterised micro-template. I wish I have an ability to use it in a manner of function, like
Code:<?
$paramValue2 = 'test';
get_component('article', 'paramValue1', $paramValue2);
?>
This could be usefull when component contains PHP code that should change it's behavior due to parameters.
Using the DynPages plugin you have this possibility, when including the component on a page.
If you want to use it from the template, use a function like this:
Code:
function get_component_with_params($name, $params=array()) {
global $args;
if (isset($args)) $saved_args = $args;
$args = $params;
get_component($name);
if (isset($saved_args)) $args = $saved_args; else unset($args);
}
In the component use the global variable $args, e.g.
Code:
global $args;
echo "Parameter 1 = $args[0]";
Call with
Code:
get_component_with_params('article', array('paramValue1','paramValue2'));