public function saludo($nombre) { // View::set("name", $nombre); // View::set("title", "Custom MVC"); // View::render("front\\home"); $templates = new Engine('../src/App/Views/front/'); echo $templates->render('error', ['name' => 'Jonathan']); }
/** * {@inheritdoc} */ public function render($template, $value) { //Performance: if there are no '%' fallback to Engine if (strstr($template, '%') == false) { return parent::render($template, $value); } $result = $template; if (!is_array($value)) { $value = array('' => $value); } foreach (new NestedKeyIterator(new RecursiveArrayOnlyIterator($value)) as $key => $value) { $pattern = "/" . $this->left . $key . "(%[^" . $this->right . "])?" . $this->right . "/"; preg_match_all($pattern, $template, $matches); $substs = array_map(function ($match) use($value) { return $match !== '' ? sprintf($match, $value) : $value; }, $matches[1]); $result = str_replace($matches[0], $substs, $result); } return $result; }
/** * Renders template. * @return void * @internal */ public function renderChildTemplate($name, array $params = array()) { $name = $this->engine->getLoader()->getChildName($name, $this->name); $this->engine->render($name, $params); }
public function saludo($nombre) { $templates = new Engine('../src/App/Views/front/'); echo $templates->render('error', ['name' => 'Jonathan']); }