GetSimple Support Forum
QUESTION Best way to wrap "get_component()" - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: Developer Discussions (http://get-simple.info/forums/forumdisplay.php?fid=8)
+--- Thread: QUESTION Best way to wrap "get_component()" (/showthread.php?tid=9969)



Best way to wrap "get_component()" - tempUser - 2017-08-30

Hello all,

In my theme i must to define if get_component('component-xyz') return null value.
I implement this function. 

PHP Code:
/**
 * This return get_component() function in a string
 *
 * @param string $id - ID of the component
 * @return string
 */
function return_get_component($id)
{
    
ob_start();
    
get_component($id);
    
$html ob_get_clean();

    return 
$html;


In this mode i can check if component return empty value (simply using "if" statement).

Do you resolve this problem in other way?


RE: Best way to wrap "get_component()" - hameau - 2017-09-02

(2017-08-30, 01:11:42)tempUser Wrote: Do you resolve this problem in other way?

If your method works for you, then use it!

It is possible to test for existence of a component, for example see this wiki page, but your solution seems elegant.