PHP Classes

PHP Templating Engine: Process templates in PHP, JSON and CSS formats

Recommend this page to a friend!
  Info   View files Example   View files View files (20)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 42 All time: 10,839 This week: 560Up
Version License PHP version Categories
php__templating_engi 1.0.0MIT/X Consortium ...5PHP 5, Templates
Description 

Author

This package can process templates in PHP, JSON, and CSS formats.

It can take as parameters the template content as a string, the language of the template data, and an array of parameter values.

The package can replace the template data with parameter values and returns the processed template as a string.


They said it couldn't be done. So I applied a new approach and was able to do it. So not only can the example code rewrite css and html files that have php vars in them, but also can read the made files and save the output to a variable for echoing later.

Picture of jon
Name: jon <contact>
Classes: 5 packages by
Country: New Zealand New Zealand
Age: ???
All time rank: 415117 in New Zealand New Zealand
Week rank: 170 Up1 in New Zealand New Zealand Up

Example

<?php

session_start
();

// takes a template in html or css or json and replaces "syntaxed" php vars with their php values;
include('functions/php_templator.php');
   
?>

<html>

    <style>
        p{
            font-size:1rem;
            font-family:Arial;
        }
    </style>
   
    <body>
        <center>
   
    <?php

   
/***********************************************************************************************************************************************

    an html file;
    the change can be seen in the broswer inspector
   
    ***********************************************************************************************************************************************/


    // ev.php - usage is ev($var) and it'll echo the var and put a <br> in there afterwards;
   
include('functions/ev.php');

   
// the file name
   
$file_php = 'template.html';
   
$file_type = 'php';

   
// get the file contents of the template file
   
$contents_php = file_get_contents($file_php);

   
// assign some variables to be used in the template;
   
$V = new stdclass();
   
$V->php_p__class_var = 'php_p__class_var';
   
$V->php_button__id_var = 'php_button__id_var';
   
$V->php_button__class_var = 'php_button__class_var';
   
$V->php_text_var = 'an html file. <br>Inspect the html in the broswer to see that the php values have been applied to the correct html tags.<br><p class="p__class2">a css file: <br>this text shows that php values can be used in stylsheets, whilst allowing the developer to continue developing css stylesheets using the colored stylising from their IDE (code editor)</p>';
   
$_SESSION['varname'] = 'session_varname';
           
   
// create html from the template with all the vars used in it;
   
$result_html = php_templator($file_type, $contents_php, $V);

   
// echo the html
   
ev($result_html);



   
/***********************************************************************************************************************************************

    a css file;
    the change can be seen on the top line of text "wind in the willows";
   
    ***********************************************************************************************************************************************/



    // assign some variables to be used in the template;
   
$V = new stdclass();
   
$V->p__fontsize = '2rem';
   
$V->p__fontfamily = '\'Sans Serif\'';
   
$_SESSION['varname'] = 'green';

   
// the file name
   
$file_css = 'stylesheet2.css';
   
$file_type = 'css';

   
$contents_css = file_get_contents($file_css);
   
$result_css = php_templator($file_type, $contents_css, $V);
   
   
ev($result_css);



   
/***********************************************************************************************************************************************

    a json file;

    ***********************************************************************************************************************************************/

?>
<p>a json file:</p>
    <br>
    <p>the correct json php var values have been placed.</p>
<?php

   
// takes a template in json and replaces "syntaxed" php vars with their values;
   
include('functions/templater_json.php');

   
// include the "echo pre" function
   
include('functions/evp.php');

   
// this is for a json file templator
   
$file_json = 'template.json';
   
$file_type = 'json';

   
// get the json file
   
$contents_json = file_get_contents($file_json);

   
// assign some variables to be used in the template;
   
$V = new stdclass();
   
$V->html_id = 'php_html_id_var';
   
$V->html_class = 'php_html_class_var';
   
$_SESSION['varname'] = 'php_session_var';

   
// templater renders the json file with replaced php vars in it ($V->asdf = "asdf_value" and $V->div_id = "id" and $_SESSION['varname'] = "session_varname");
   
$result_json = php_templator($file_type, $contents_json, $V);

   
// usage = evp($var);
   
evp($result_json);



?>

        </center>
       
    </body>
   
</html>


  Files folder image Files  
File Role Description
Files folder imagetemplating_engine (12 files, 2 directories)

  Files folder image Files  /  templating_engine  
File Role Description
Files folder imagefunctions (7 files)
Files folder imagejs (1 file)
  Accessible without login Plain text file editor.php Aux. Auxiliary script
  Accessible without login Plain text file index.php Example Example script
  Accessible without login Plain text file stylesheet.css Data Auxiliary data
  Accessible without login Plain text file stylesheet2.css Data Auxiliary data
  Accessible without login Plain text file template.html Data Template example
  Accessible without login Plain text file template.json Data Auxiliary data
  Accessible without login Plain text file template.php Aux. Auxiliary script
  Accessible without login Plain text file template_00001.html Data Template data
  Accessible without login Plain text file template_00001.php Aux. Auxiliary script
  Accessible without login Plain text file tmp.php Data Template script
  Accessible without login Plain text file tmp_001.php Aux. Auxiliary script
  Accessible without login HTML file tmp_template_00001.html Doc. Documentation

  Files folder image Files  /  templating_engine  /  functions  
File Role Description
  Accessible without login Plain text file echo_var.php Aux. Auxiliary script
  Accessible without login Plain text file ev.php Aux. Auxiliary script
  Accessible without login Plain text file evp.php Aux. Auxiliary script
  Accessible without login Plain text file php_templator.php Aux. Auxiliary script
  Accessible without login Plain text file templater.php Aux. Auxiliary script
  Accessible without login Plain text file templater_json.php Aux. Auxiliary script
  Accessible without login Plain text file templater_php.php Aux. Auxiliary script

  Files folder image Files  /  templating_engine  /  js  
File Role Description
  Accessible without login Plain text file jquery-3.3.1.js Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:42
This week:0
All time:10,839
This week:560Up