Recommend this page to a friend! |
Download .zip |
Info | Example | View files (6) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2024-01-19 (5 days ago) | Not yet rated by the users | Total: 20 This week: 20 | All time: 11,133 This week: 5 |
Version | License | PHP version | Categories | |||
tinybinder 1.0 | MIT/X Consortium ... | 5 | PHP 5, Templates |
Description | Author | |||||||||||||
This class can replace template variables with function results. |
|
A super lightweight templating class that merges content, and the results of custom functions, with an HTML file.
Clone the repository or download the TinyBinder.php
file and include it in your project.
Merge single values:
<?php
$tinyBinder = new TinyBinder('path/to/template.html');
$tinyBinder->addAsset('name', 'John');
$tinyBinder->addAsset('age', '25');
$result = $tinyBinder->getHtml();
Merge multiple values:
<?php
$tinyBinder = new TinyBinder('path/to/template.html');
$tinyBinder->addAssets(['name' => 'John', 'age' => 25]);
$result = $tinyBinder->getHtml();
Debug:
<?php
$tinyBinder = new TinyBinder('path/to/template.html');
$tinyBinder->debug();
Save time by using the static shorthand. This is equivalent to calling addAssets
, getHtml
and debug
:
<?php
$result = TinyBinder::make('path/to/template.html', ['name' => 'John', 'age' => 25], true);
1) Add a variable placeholder
Wrap a variable placeholder in double curly braces. In the example below, {{ $name }}
will be replaced with the content of the variable $name
that you pass in using either the addAsset
or addAssets
method. The variable name in your HTML template must start with a $
character.
<html>
{{ $name }}
</html>
2) Add a function placeholder
Wrap a function placeholder in double curly braces. In the example below, {{ @time }}
will be replaced with the result of the $time
closure in the functions.php
file. Functions are merged automatically. The function name in your HTML template must start with a @
character.
<html>
{{ @time }}
</html>
Add a new closure to the included functions.php
file:
$time = function() {
return date('H:i:s');
};
The name of the variable that holds the closure result must match the function placeholder name. The function name in the template must start with a @
character.
<html>
{{ @time }}
</html>
Feel free to contribute or fix any issues. Create a pull request or open an issue for discussion.
This project is licensed under the MIT License.
A super lightweight templating class that merges content, and the results of custom functions, with an HTML file.
Clone the repository or download the TinyBinder.php
file and include it in your project.
Merge single values:
<?php
$tinyBinder = new TinyBinder('path/to/template.html');
$tinyBinder->addAsset('name', 'John');
$tinyBinder->addAsset('age', '25');
$result = $tinyBinder->getHtml();
Merge multiple values:
<?php
$tinyBinder = new TinyBinder('path/to/template.html');
$tinyBinder->addAssets(['name' => 'John', 'age' => 25]);
$result = $tinyBinder->getHtml();
Debug:
<?php
$tinyBinder = new TinyBinder('path/to/template.html');
$tinyBinder->debug();
Save time by using the static shorthand. This is equivalent to calling addAssets
, getHtml
and debug
:
<?php
$result = TinyBinder::make('path/to/template.html', ['name' => 'John', 'age' => 25], true);
1) Add a variable placeholder
Wrap a variable placeholder in double curly braces. In the example below, {{ $name }}
will be replaced with the content of the variable $name
that you pass in using either the addAsset
or addAssets
method. The variable name in your HTML template must start with a $
character.
<html>
{{ $name }}
</html>
2) Add a function placeholder
Wrap a function placeholder in double curly braces. In the example below, {{ @time }}
will be replaced with the result of the $time
closure in the functions.php
file. Functions are merged automatically. The function name in your HTML template must start with a @
character.
<html>
{{ @time }}
</html>
Add a new closure to the included functions.php
file:
$time = function() {
return date('H:i:s');
};
The name of the variable that holds the closure result must match the function placeholder name. The function name in the template must start with a @
character.
<html>
{{ @time }}
</html>
Feel free to contribute or fix any issues. Create a pull request or open an issue for discussion.
This project is licensed under the MIT License.
Files | / | demo |
File | Role | Description |
---|---|---|
RUNME.php | Example | Example script |
template.html | Data | Demo template |
Files | / | src |
File | Role | Description |
---|---|---|
functions.php | Aux. | Auxiliary script |
TinyBinder.php | Class | Class source |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.