39 lines
999 B
PHP
39 lines
999 B
PHP
<?php
|
|
|
|
/*
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
@param two arguments :
|
|
1. html files to include in front
|
|
- can be a string of 1 filename
|
|
- or an array of strings of filenames
|
|
( https://stackoverflow.com/q/4747876/9497573 )
|
|
2. list of variables to make available to this files
|
|
- in the form of key => val
|
|
- recommanded to do it with compact()
|
|
ex: create_html( "file.html", compact("var1","var2",) );
|
|
ex: create_html( array("file1.html", "file2.html"), array("var1"=>"value") );
|
|
@return a string of html code
|
|
|
|
using ob_start() and ob_get_clean()
|
|
allows to have php expansion inside the html loaded
|
|
in opposition to the methode file_get_contents()
|
|
|
|
https://stackoverflow.com/a/4402045/9497573
|
|
*/
|
|
function create_html($files, $vars) {
|
|
$files = (array)$files;
|
|
|
|
$html_dir = plugin_dir_path(__DIR__).'html/';
|
|
extract($vars);
|
|
|
|
ob_start();
|
|
foreach($files as $file) {
|
|
include($html_dir.$file);
|
|
}
|
|
$html = ob_get_clean();
|
|
|
|
return $html;
|
|
}
|
|
|
|
?>
|