PHP Classes

STPL: Render templates using PHP code scripts

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 127 All time: 9,408 This week: 560Up
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: 16206 in Serbia Serbia
Week rank: 195 Up1 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 (6)  
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 (6)  /  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 (6)  /  template  /  pages  
File Role Description
  Accessible without login Plain text file welcome.php Example Example script

  Files folder image Files (6)  /  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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:127
This week:0
All time:9,408
This week:560Up
User Comments (1)
A very helpful class for templating in core php
6 years ago (Dinesh Suthar)
70%StarStarStarStar