Skip to content

Commit e6c7d62

Browse files
committed
Feat: Template render
1 parent e67a295 commit e6c7d62

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ composer.phar
33

44
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
55
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6-
# composer.lock
6+
composer.lock

composer.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "nigatedev/diyan",
3+
"description": "The Nigatedev PHP framework template engine",
4+
"type": "library",
5+
"license": "MIT",
6+
"autoload": {
7+
"psr-4": {
8+
"Nigatedev\\Diyan\\": "src/"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "Abass Ben Cheik",
14+
"email": "[email protected]"
15+
}
16+
],
17+
"require": {}
18+
}

src/Diyan.php

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/*
3+
* This file is part of the Nigatedev PHP framework core Application
4+
*
5+
* (c) Abass Ben Cheik <[email protected]>
6+
*/
7+
8+
namespace Nigatedev\Diyan;
9+
10+
11+
/**
12+
* View render
13+
*
14+
* @Author Abass Ben Cheik <[email protected]>
15+
*/
16+
class Diyan
17+
{
18+
/**
19+
* @param
20+
*
21+
* @return render final view
22+
*/
23+
public function render($view)
24+
{
25+
$baseLayout = $this->getBaseLayout();
26+
$viewContent = $this->getViewContent($view);
27+
28+
return str_replace(["{{content}}", "{{title}}"], [$viewContent, strtoupper($view)], $baseLayout);
29+
}
30+
31+
/**
32+
* @return base template
33+
*/
34+
public function getBaseLayout()
35+
{
36+
ob_start();
37+
require_once "../views/layouts/base.php";
38+
return ob_get_clean();
39+
}
40+
41+
/**
42+
* @param the view giving from the Router, E.g: Nigatedev\Core\Router::get("/", "home") method. will load path/to/views/home.php
43+
*
44+
* @return only view content
45+
*/
46+
public function getViewContent($view)
47+
{
48+
ob_start();
49+
require_once "../views/$view.php";
50+
return ob_get_clean();
51+
}
52+
53+
}

0 commit comments

Comments
 (0)