GetSimple Support Forum

Full Version: Function: is_component() and return_component().
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
For those times you need to test the existence of a component or run some extra code on it before executing.

is_component()

Pass the id of the component to this function. It will return either true or false, depending on whether the component exists.
Code:
function is_component($id) {
    if (file_exists(GSDATAOTHERPATH.'components.xml')) {
        $d = getXML(GSDATAOTHERPATH.'components.xml');
        return count($d->xpath('//item[slug="'.$id.'"]'))>0?true:false;
    }
}

return_component()

Pass the id of the component to this function. It will return either the contents of the component in the form of a string or false, depending on whether the component exists.
Code:
function return_component($id) {
    if (file_exists(GSDATAOTHERPATH.'components.xml')) {
        $d = getXML(GSDATAOTHERPATH.'components.xml');
        $v = $d->xpath('//item[slug="'.$id.'"]/value');
        return !$v?false:stripslashes(htmlspecialchars_decode((string)$v[0],ENT_QUOTES));
    }
}

Can I use it with the per page components function?

I do not think this is compatible with my per page components function, but I didn’t test it. I will not work on making it compatible if it isn’t because these two functions should be seen as extensions to the core functions and not as extensions to another extension.