Skip to content

OmarElebiary/simple-template-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

simple-template-parser

A simple php template parser.

template-parser replaces all placeholders in html template with actual values.

Usage

Simply instantiate TemplateParser with a link to the HTML template.

Example

Let's say that we have an html template called profile.tpl :

<h1>{username} profile</h1>

<p><b>Name:</b> {name}</p>
<p><b>Email:</b> {email}</p>
<p><b>Location:</b> {location}</p>

You can parse it like this:

include("TemplateParser.php");

// Load the template file
$profile = new TemplateParser("profile.tpl");

$data = array("username" => "user_one", 
              "name" => "Ben",
              "email" => "ben@example.com",
              "location" => "Egypt");

$profile->set_data($data);

echo $profile->output();

Output:

<h1>user_one profile</h1>

<p><b>Name:</b> Ben</p> 
<p><b>Email:</b> ben@example.com</p> 
<p><b>Location:</b> Egypt</p>

The returned html string contains all the values instead the placeholders.

About

Simple HTML template parser in php

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors