Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
optional parameters of "component"
#4
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'));
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply


Messages In This Thread
optional parameters of "component" - by bugman - 2011-06-08, 21:29:05
optional parameters of "component" - by bugman - 2011-06-08, 21:46:44
optional parameters of "component" - by mvlcek - 2011-06-08, 21:53:29
optional parameters of "component" - by bugman - 2011-06-08, 22:03:32
optional parameters of "component" - by bugman - 2011-06-08, 22:23:43
optional parameters of "component" - by mvlcek - 2011-06-18, 07:23:05
optional parameters of "component" - by mvlcek - 2011-06-18, 21:33:07
optional parameters of "component" - by ccagle8 - 2011-06-20, 09:10:54
optional parameters of "component" - by mvlcek - 2011-06-20, 16:27:53
optional parameters of "component" - by mvlcek - 2011-06-20, 19:36:30
optional parameters of "component" - by mvlcek - 2011-06-20, 20:45:03
optional parameters of "component" - by mvlcek - 2011-06-20, 23:55:27
optional parameters of "component" - by mvlcek - 2011-06-21, 05:28:08



Users browsing this thread: 1 Guest(s)