Build a template

@param string $filename
@param mixed $data
@param boolean $return
@return string
766412
protected function load($filename, $data = array(), $return = false)
    {
        $template = $this->createSubTemplate();

        try {
            return $template->renderTemplate($filename, $data, $return);
        } catch (\Exception $exception) {
            if (!empty($this->log))
            {
                $this->log->error("Failed to render template " . $filename, $exception);
            }
            return '';
        }
    }
332885
protected function renderTemplate($input, $outputFile, $template, $templates, $data = [])
    {
        $paths = [$templates];

        if ($templates = $input->getOption('templates')) {
            $paths []= $templates;
        }

        $paths = array_filter($paths);

        $loader = new Twig_Loader_Filesystem($paths);
        $twig = new Twig_Environment($loader);


        $template = $twig->loadTemplate($template);

        $dataOption = $input->getOption('data');

        if (file_exists($dataOption)) {
            $dataOption = file_get_contents($dataOption);
        }

        $dataOption = json_decode(stripcslashes($dataOption), true);

        if (!is_array($dataOption)) {
            $dataOption = [];
        }

        $data = array_merge($data, $dataOption);

        @mkdir(dirname($outputFile), 0755, true);
        file_put_contents($outputFile, $template->render($data));
    }
31434
private function parseTemplate($filename, $data)
    {
        if (is_array($data)) {
            $this->_templateData = $data;
        } else if (is_object($data)) {
            if (method_exists($data, 'getTemplateData')) {
                $this->_templateData = $data->getTemplateData();
            } else {
                $this->_templateData = (array)$data;
            }
        } else {
            $this->_templateData = array('variable' => $data);
        }

        $this->allowRecursion = (!empty($this->_templateData['_allowRecursion']) ? true : false);

        $filename = $this->locateViewFile($filename);

        if ($filename) {
            $this->setCurrentTemplate($filename);

            ob_start();
            include $filename;
            $info = ob_get_contents();
            ob_end_clean();

            return $info;
        }

        return false;
    }
913455
public function create($fileName, $data)
    {
        $path = $this->getPathBase($fileName);

        if (file_exists($path)) {
            return;
        }

        $data = serialize($data);

        return file_put_contents($path, $data);
    }
176836
protected function compile($template, $data)
    {
        foreach($data as $key => $value)
        {
            $template = preg_replace("/\\$$key\\$/i", $value, $template);
        }
        return $template;
    }
1124135
public function loadTemplate($template, $data = array(), $process = true)
    {
        $path = $this->findTemplate($template);

        if (! $path) {
            unset($this->_paths[$template.'.php']);
            throw new LibBaseTemplateException($template.' template not found for '.$this->getIdentifier());
            return false;
        }

        return $this->loadFile($path, $data, $process);
    }
798610
public function success($message = null, $data = array(), $return = false)
    {
        if (!empty($data)) {
            foreach ($data as $key => $value) {
                $this->add($key, $value);
            }
        }
        $json = $this->jsonEncode(
            array(
                'success' => true,
                'message' => $message,
                'data' => $this->_data,
            )
        );
        if (!$return) {
            echo $json;
            Yii::app()->end();
        } else {
            return $json;
        }
    }
550578
private static function processAsset($string, $name, $return, $filenamePath)
    {
        $filePath = $filenamePath;
        if (file_exists($filenamePath)) {
            list($base, $htmlBase, $filePath) = AssetsParser::calculateAssetPath($string, $name, $return, $filenamePath);
            //Creamos el directorio si no existe
            GeneratorHelper::createDir($base . $htmlBase);
            //Si se ha modificado
            if (!file_exists($base . $filePath) || filemtime($base . $filePath) < filemtime($filenamePath)) {
                if ($htmlBase === 'css') {
                    self::processCssLines($filenamePath);
                }
                self::putResourceContent($name, $filenamePath, $base, $filePath);
            }
        }

        return $filePath;
    }
437875
public function render($file, $data) {
        $template = $this->engine->loadTemplate($file);

        return $template->render($data);
    }
439119
public function getPhotoImage($data = null, $returnTableRow = true, $size = 0) {
		$result = $this->_getValueForPhotoImageBase($data, $returnTableRow, $size);

		return $result;
	}
163730
public function mail($template, $data = array(), &$css = array())
    {
        $this->twig->addFunction(new \Twig_SimpleFunction('css', function ($file) use (&$css) {
            $css[] = $file;
        }));
        $template = $this->twig->loadTemplate($template);
        return $template->render($data);
    }
1299037
public function makeHtml($template, $data=null)
	{
		$content = $this->render($template, $data);
		return File::write($this->getHtmlFile($template), $content); 
	}
842289
public function getView($filename, $data = null)
    {
        // $data = ($data === null) ? $this->_data : $data;
        return $this->getTemplateFile($this->getTemplateFolder().$filename, $data);
    }
910151
public static function view(string $path, array $data = [], bool $return = false)
  {
    $data = array_merge(GlobalVariables::get(), $data);

    if ($return) return self::$viewComponent->make($path, $data);

    $view = new View;

    $view->compiled = self::$viewComponent->make($path, $data);

    return $view;
  }
50318
def template(name, datas)
      file = template_path(name)
      content = File.read(file)

      datas.each do |k, v|
        k = "<%= #{k} %>"
        content = content.gsub(k, v)
      end
      return content
    end
614574
public static function dump($data, $return = false)
    {
        $result = '';

        if (Fabrication::isCli()) {
            $end = "\n";
        } else {
            $end = "<br />\n";
        }

        if (is_object($data)) {

            $classname = get_class($data);

            $result = str_repeat('-', 80) . $end .
                    "\t" . __METHOD__ . ' Type: ' . gettype($data) . "\tReturn:" . var_export($return, true) . $end .
                    str_repeat('-', 80) . $end .
                    "Object Instance: $classname: $end" .
                    "Object Methods $end";

            $class_methods = get_class_methods($data);
            if (count($class_methods) > 0) {
                foreach ($class_methods as $method) {
                    $result.="\t" . $method . $end;
                }
            } else {
                $result.="No methods found.$end";
            }

            $result.= $end;
            $result.= "Object XPath:$end";
            $result.= $end;

            switch ($classname) {

                case 'DOMAttr':
                    $result.= "DOMAttr XPath: {$data->getNodePath()}$end" .
                            $data->ownerDocument->saveXML($data);
                    break;

                case 'DOMDocument':
                    $result.= "DOMDocument XPath: {$data->getNodePath()}$end" .
                            $data->saveXML($data);
                    break;

                case 'DOMElement':
                    $result.= "DOMElement XPath: {$data->getNodePath()}$end" .
                            $data->ownerDocument->saveXML($data);
                    break;

                case 'DOMNodeList':
                    for ($i = 0; $i < $data->length; $i++) {
                        $result.= "DOMNodeList Item #$i, " .
                                "XPath: {$data->item($i)->getNodePath()}$end" .
                                "{$data->item($i)->ownerDocument->saveXML($data->item($i))}$end";
                    }
                    break;

                default: $result.= var_export($data, true);
            }
        }

        if (is_array($data)) {

            $result = $end .
                $end .
                str_repeat('-', 80) . $end .
                "| DUMP Type:" . gettype($data) . "\tReturn:" . var_export($return, true) . $end .
                str_repeat('-', 80) . $end .
                $end;
        }

        if (is_string($data)) {
            $result = var_export($data, true);
        }

        if (is_int($data)) {
            $result = var_export($data, true);
        }

        if ($return) {
            return $result . $end;
        } else {
            echo $result . $end;
        }
    }
605926
public static function asset($string, $name = null, $return = true)
    {

        $filePath = '';
        if (!file_exists($filePath)) {
            $filePath = BASE_DIR . $string;
        }
        $filenamePath = AssetsParser::findDomainPath($string, $filePath);

        $filePath = self::processAsset($string, $name, $return, $filenamePath);
        $basePath = Config::getParam('resources.cdn.url', Request::getInstance()->getRootUrl());
        $returnPath = empty($name) ? $basePath . '/' . $filePath : $name;
        return $return ? $returnPath : '';
    }