Skip to content

Commit cfc9be6

Browse files
author
polarnix
committed
added consutor to view to inherit paths config
1 parent cfbfdef commit cfc9be6

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

composer.lock

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/components/header.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
<p><?php echo $desc; ?></p>
33
<p><?php echo $view->escape($htmlval); ?></p>
44

5-
<p><?php echo $view->escape($desc, 'uppercase|randomize'); ?></p>
5+
<p><?php echo $view->escape($desc, 'uppercase|randomize'); ?></p>
6+
7+
<?php
8+
echo $view->render('title');
9+
?>

examples/components/title.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<h1>
2+
Welcome to my site
3+
</h1>

examples/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
$config = [
88
__DIR__ . '/components',
9-
__DIR__ . '/pages'
9+
__DIR__ . '/pages',
1010
];
1111
$template = new TemplateEngine($config);
1212

src/TemplateEngine.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function render(string $slug, array $args = []) {
1313
$slug = $slug.'.php';
1414
$paths = $this->config;
1515

16-
$view = new View();
16+
$view = new View($paths);
1717
array_push($args, $view);
1818

1919
$paths = array_map(function($path) use ($slug) {
@@ -45,6 +45,10 @@ public function render(string $slug, array $args = []) {
4545
}
4646

4747
class View extends TemplateEngine {
48+
public function __construct(array $config = []) {
49+
parent::__construct($config);
50+
}
51+
4852
public function escape(string $val, string $mods = ''): string {
4953
if(!$mods) {
5054
return htmlspecialchars($val);

0 commit comments

Comments
 (0)