PHP Template Previewer
, (*1)
PHP template previewer for designers testing their framework views without the working backend code., (*2)
Originally created for a personal project using the Phalcon PHP framework and its templating system Volt., (*3)
Disclaimer:
This is my first composer as well as open source project, so if you see anything that needs improving, don't hesitate
and tell me. Read my introduction post, (*4)
List of implemented frameworks
Extending the framework support
You can make a request for any framework that you want to use this library into, or even better, make a pull request with your own framework strategy.
Just implement the IFrameworkStrategy interface. Use the files under the FrameworkStrategies folder as an example., (*5)
What's new
v0.2.0
- Added Json file support for the variable files
Installation
Composer
This library is available in packagist.org, you can add it to your project
via Composer., (*6)
In the "require" section of your composer.json file:, (*7)
Always up to date (bleeding edge, API not guaranteed stable), (*8)
"antonienko/php-template-previewer": "dev-master"
Specific minor version, API stability, (*9)
"antonienko/php-template-previewer": "0.2.*"
If you have any problems with the minimum-stability setting try appending @dev to the version, (*10)
"antonienko/php-template-previewer": "0.2.*@dev"
Sample Usage
Phalcon Framework
DesignController with an action View that gets two parameters: $controller
and $view
, which are the name of the controller and action view that you want to render.
You would call the url like this: http://localhost/designTest/view/controllername/viewname
but you are not restricted to use it in this way, (*11)
namespace app\controllers;
use antonienko\PhpTempPrev\FrameworkStrategies\PhalconStrategy;
use antonienko\PhpTempPrev\FileStrategies\IniFileStrategy;
use antonienko\PhpTempPrev\Previewer;
class DesignTestController extends ControllerBase
{
public function viewAction($controller, $view)
{
$view_variables_file = APP_PATH . 'templateHelpers/' . $controller . '/' . $view . '.ini';
$layout_variables_file = APP_PATH . 'templateHelpers/general.ini';
$previewer = new Previewer(new PhalconStrategy($this->view));
$previewer->render("$controller/$view", new IniFileStrategy([$layout_variables_file, $view_variables_file]));
}
}
Var files
You pass to the render a class implementing IFileStrategy
initialized with an array of var files. In case of having the same variable defined in two of the var files, the last one will prevail., (*12)
The variables are separated in three categories: scalars, arrays and objects., (*13)
If you want to get an idea of how the var files work take a look at the test fixtures., (*14)
Lincensed under The MIT License (MIT). See the LICENSE file for more details., (*15)