PHP Classes

STPL: Render templates using PHP code scripts

Recommend this page to a friend!
  Info   View files Example   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 126 All time: 9,382 This week: 181Up
Version License PHP version Categories
stpl 1.0.0BSD License7.2PHP 5, Templates
Description 

Author

This class can render templates using PHP code scripts.

It takes a given PHP script that mixes data and code that calls the class to outputs data that is inserted in placeholder positions of the template.

Currently it can replace placeholder positions with variable values taken from parameters passed as associative arrays or replace sections defined using the return values of callback function.

Picture of Aleksandar Zivanovic
  Performance   Level  
Name: Aleksandar Zivanovic <contact>
Classes: 16 packages by
Country: Serbia Serbia
Age: 30
All time rank: 16237 in Serbia Serbia
Week rank: 312 Up2 in Serbia Serbia Up
Innovation award
Innovation award
Nominee: 4x

Example

<?php

require_once __DIR__ . '/STPL.php';

$template = __DIR__ . '/template/pages/welcome.php';

$data = [
   
'user' => ['firstName' => 'Aleksandar', 'lastName' => 'Zivanovic'],
   
'queryTime' => microtime(true),
];

STPL::Render($template, $data, false);


  Files folder image Files  
File Role Description
Files folder imagetemplate (1 file, 2 directories)
Accessible without login Plain text file index.php Example Entry file for example.
Plain text file STPL.php Class Simple PHP template engine, without using any fancy custom syntax, it relies only on pure php and plain html

  Files folder image Files  /  template  
File Role Description
Files folder imagepages (1 file)
Files folder imagepartials (2 files)
  Accessible without login Plain text file base.php Example Example script

  Files folder image Files  /  template  /  pages  
File Role Description
  Accessible without login Plain text file welcome.php Example Example script

  Files folder image Files  /  template  /  partials  
File Role Description
  Accessible without login Plain text file bottom.php Example Example script
  Accessible without login Plain text file top.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:126
This week:0
All time:9,382
This week:181Up
User Comments (1)
A very helpful class for templating in core php
5 years ago (Dinesh Suthar)
70%StarStarStarStar