Skip to content

Php template engine to introduce myself with the concept of templating engine

Notifications You must be signed in to change notification settings

lilianQ-Q/Tangerine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tangerine - Template engine

Tangerine is a project to introduce myself with the concept of templating engine.

Prerequisites

  • Php8.0
  • PhpAutoloader (Stable Release)

Installation

  1. Clone the repo
    $> git clone https://lilianQ-Q/Tangerine.git
  2. Configure your autoloader
    {
    	"Tangerine\\" : "path/to/tangerine/src/folder"
    }
  3. If you want to run library's tests, don't forget to download the lib's dependencies. Project's dependencies are listed in Tangerine/conf/tinypm.json)
    $> make libupdate
    $> make tests

Usage


Declaration

First, create a Engine object and then you'll be able to render html files like this

use Tangerine\Engine;

$engine = new Engine('path/to/cache/folder', 'path/to/views/folder');

$engine->render('index.html');

Template file


Yields & Blocks

A common usage of yield section is this one. In your layout file declare a yield section.

<!-- baselayout.html in views folder -->
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>Test</title>
	</head>
	<body>
		{% yield content %}
	</body>
</html>

Then in your index view, extends this layout and declare a new block.

<!-- index.html in views folder -->
{% extends layout.html %}

{% block content %}

<div class="demo_content">
	<p>Welcome to Tangerine engine, nice to meet you !</p>
</div>

{% endblock %}

And your result will be this after rendering with the Tangerine engine

<!-- This is what you'll get, and cached if enabled -->
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>Test</title>
	</head>
	<body>
		<div class="demo_content">
			<p>Welcome to Tangerine engine, nice to meet you !</p>
		</div>
	</body>
</html>

Basicly, a yield section needs to be filled via a block section. Pretty simple right ?

Extends and includes

For convention, when you want to extend a layout use the keywork extends. But if you want to include another view part, use the keywork include.

Snippets

To easily write code faster you'll find snippets support for vscode in support folder of the project.

Future Features

I'm currently learning how to create a langage support so you can have a better highlighting support for the engine.

Contact

Lilian Damiens - @damiens_lilian - [email protected]



Acknowledgments

About

Php template engine to introduce myself with the concept of templating engine

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published