Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 64 | All time: 10,406 This week: 74 |
Version | License | PHP version | Categories | |||
php_component_templa 1.0.0 | GNU Lesser Genera... | 5 | PHP 5, Templates |
This project aims to deliver an easy to use, free as in freedom and fast template engine for php (code name: yepte - yet another php template engine).
The build status of the current master branch is tracked by Travis CI:
Take a look on openhub.net.
I wanted to create a lean (in matter of lines of code and number of files) fast, extendable but expendable template engine for php. This project does not aim to shake on the throne of the big template engine available for php. They have different goals, more manpower and different ideas behind.
Personally, I like the php-text-template but sebastian has a different approach in mind (writing something to a file). Adding my goals to his project would add more complexity to his library.
Currently, this component tries to solve three problems when dealing with php templates. All Templates are stackable, meaning you can assign one template key with another template instance.
RuntimeContentBasedTemplate solve the problem to replacing content stored in a string.
FileBasedTemplate solves the problem replacing content stored in a file.
ComplexFileBasedTemplate solves the problem replacing complex content stored in a file. This is commonly known as the view in php frameworks.
CallableComplexFileBasedTemplateManager solves the problem externalise reusable template tasks. This is commonly known as the view helper pattern.
Complex content contains code like:
$isFoo = ($bar === 'foo');
if ($isFoo) {
/.../
} else {
/... something else/
}
Callable is an other word for the famous view helper design pattern. The template provides a method called "registerCallable" to register a callable and bind it to a name.
//assuming the file in the relative path 'template.phtml' has the following content
//<?php $this->foobar('foo', 'bar');
$myViewHelper = function($foo, $bar) {
return 'there is no ' . $foo . ' without a ' . $bar;
}
$template = new CallableComplexFileBasedTemplateManager('template.phtml');
$template->registerCallable('foobar', $myViewHelper);
echo $template->render() . PHP_EOL;
//expected result: there is no foo without a bar
Well, it is up to you and the code is pretty flexible.
My two cents are, limit yourself to foreach. if/else is one step further to "adding business logic to the template". switch is another step into this direction.
use Net\Bazzline\Component\Template\RuntimeContentBasedTemplate;
//create a instance
$template = new RuntimeContentBasedTemplate();
//set content
$template->setContent('there is no {one} without a {two}');
//assign variable one by one ...
$template->assignOne('one', 'foo');
//... or by providing an array
$template->assignMany(array('one' => 'foo'));
//you can also assign a template to a template
// this is used if a layout template is defined with a {content} key for e.g.
$template->assignOne('content', $otherTemplate);
//you can render it in different ways
//1) explicit calling the method
echo $template->render();
//2) casting it to a string
echo (string) $template;
//3) using it as a function
// you can also provide all optional parameters like in the constructor
echo $template();
mkdir -p vendor/net_bazzline/php_component_template
cd vendor/net_bazzline/php_component_template
git clone https://github.com/bazzline/php_component_template .
composer require net_bazzline/php_component_template:dev-master
API is available at bazzline.net.
Star it if you like it :-). Add issues if you need it. Pull patches if you enjoy it. Write a blog entry if you use it :-D.
Files (22) |
File | Role | Description | ||
---|---|---|---|---|
source (10 files) | ||||
test (6 files) | ||||
.scrutinizer.yml | Data | Auxiliary data | ||
.travis.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpunit.xml.dist | Data | Auxiliary data | ||
README.md | Doc. | Read me |
Files (22) | / | source |
File | Role | Description |
---|---|---|
AbstractFileBasedTemplate.php | Class | Class source |
AbstractTemplate.php | Class | Class source |
CallableComplexFil...TemplateManager.php | Class | Class source |
ComplexFileBasedTemplate.php | Class | Class source |
DelimiterInterface.php | Class | Class source |
ExpressiveTemplateAdapter.php | Class | Class source |
FileBasedTemplate.php | Class | Class source |
RuntimeContentBasedTemplate.php | Class | Class source |
TemplateDumper.php | Class | Class source |
TemplateInterface.php | Class | Class source |
Files (22) | / | test |
File | Role | Description |
---|---|---|
bootstrap.php | Aux. | Auxiliary script |
CallableComplexFil...lateManagerTest.php | Class | Class source |
ComplexFileBasedTemplateTest.php | Class | Class source |
ExpressiveTemplateAdapterTest.php | Class | Class source |
FileBasedTemplateTest.php | Class | Class source |
RuntimeContentBasedTemplateTest.php | Class | Class source |
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 |
php_component_templa-2022-05-11.zip 20KB | |
php_component_templa-2022-05-11.tar.gz 12KB | |
Install with Composer |
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.