protected function template($template=null,$variables=null,$return=false)
    {
        if (!$template) {
            $template = Utility::getClassName($this);
        } else if (gettype($template)=="array") {
            if (gettype($variables)=="boolean") {
                $return = $variables;
            }
            $variables = $template;
            $template = Utility::getClassName($this);
        }

        $currentDir = $this->getWidgetFolder();

        $themeBase = $this->getThemeBase();
        if ($themeBase && is_file($currentDir."/$template.$themeBase.tpl.php")) {
            $template.=".$themeBase";
        }

        //Try the template with base, if found then use it
        if (!is_file($currentDir."/$template.tpl.php")) {
            throw new \Exception("Could not find template [$template.tpl.php]");
        }

        ob_start();
        if ($variables) {
            foreach ($variables as $key=>$value) {
                $$key = $value;
            }
        }
        include $currentDir."/$template.tpl.php";
        $output = ob_get_clean();
        //$output = preg_replace('/\s+/S'," ", $output);
        if ($return) {
            return $output;
        } else {
            echo $output;
        }
        
    }