Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
optional parameters of "component"
#9
@mvlcek:

I see you are using a global variable inside your implementation, why? You can do this without leaking any data into the global scoop, that way you don’t have to bother with back-upping any already existing variables either.

This works just as well: (large bit of code directly from the GS core)
Code:
function get_component_args($id) {
    if (func_num_args() > 1) { $args = func_get_args(); array_shift($args); }
    if (file_exists(GSDATAOTHERPATH.'components.xml')) {
        $data = getXML(GSDATAOTHERPATH.'components.xml');
        $components = $data->item;
        if (count($components) != 0) {
            foreach ($components as $component) {
                if ($id == $component->slug) {
                    eval("?>" . strip_decode($component->value) . "<?php ");
                }
            }
        }
    }
}
And can be used like this, in a template:
Code:
get_component_args('credits','Zegnåt','http://zegnat.net/');
and with a component called credits:
Code:
<p>Build by <a href="<?php echo $args[1]; ?>"><?php echo $args[0]; ?></a></p>
Please stay out of the global scoop unless you need to communicate with global data.

--- --- --- --- ---

The big question for this topic to answer is: should this be implemented in the core?
“Don’t forget the important ˚ (not °) on the a,” says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
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 Zegnåt - 2011-06-18, 20:12:47
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)