Download the PHP package asgard/templating without Composer

On this page you can find all versions of the php package asgard/templating. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package templating

Templating

Build Status

Templating is a simple package which provides interfaces to build your own templating system. It also provides a PHP templating system and the Viewable class.

Installation

If you are working on an Asgard project you don't need to install this library as it is already part of the standard libraries.

composer require asgard/templating 0.*

Interfaces

TemplateEngineInterface

public function templateExists($template); #check that a template exists
public function getTemplateFile($template); #return the file corresponding to the template name
public function createTemplate(); #return a new instance of the template class (implementing TemplateInterface)

TemplateInterface

public function getEngine();
public function setEngine(TemplateEngineInterface $engine);
public function setTemplate($template);
public function getTemplate();
public function setParams(array $params=[]);
public function getParams();
public function render($template=null, array $params=[]);
public static function renderFile($file, array $params=[]);

PHP Template

The PHPTemplate class implements the TemplateInterface.

Create a new template:

$template = new Asgard\Templating\PHPTemplate('template.php', ['title'=>'Hello!']);

Set a template

$template->setTemplate('template2.php');

Get the template:

$template->getTemplate(); #template2.php

Set parameters:

$template->setParams(['title'=>'Hello!']);

Get parameters:

$template->getParams(); #['title'=>'Hello!']

Render the template:

$template->render();

Render a specific template with parameters:

$template->render('template.php', ['title'=>'Hello!']);

Statically render a template:

Asgard\Templating\PHPTemplate::renderFile('template.php', ['title'=>'Hello!']);

Viewable

The Viewable trait provides the methods so that a class can easily be rendered with templates.

Usage

class Abc {
    use \Asgard\Templating\Viewable;

    public function test($param1, $param2) {
        return 'test';
    }
}

$abc = new Abc;

$abc->setTemplateEngine($engine);
#the engine will be passed to any template used by the class
#$abc->getTemplateEngine(); to get the engine

$abc->run('test', ['param1', 'param2']);

Rendering

There are many ways a method can render the result.

public function test() {
    return 'test';
}
#run('test') returns 'test'

public function test() {
    echo 'test';
}
#run('test') returns 'test'

public function test() {
    return new MyTemplate('template.php', [/*..*/]);
}
#run('test') will call ->render() on the template and return the result

public function test() {
    $this->view = new MyTemplate('template.php', [/*..*/]);
}
#run('test') will call ->render() on $this->view and return the result

public function test() {
    $this->view = 'template';
}
#if the object as a TemplateEngine, it will create a template instance and pass 'template.php' to it.
#if not, Viewable will use its own default rendering technique.

Default rendering

When a template name is passed to $this->view, and the object does not have its own TemplateEngine, Viewable will try to solve the template file corresponding to the template name, include it and pass its own variables.

For example:

#Viewable class test method
public function test() {
    $this->title = 'Hello!';
    $this->view = 'template'; #template matches /var/www/project/templates/template.php
}

#template.php
echo '<h1>'.$title.'</h1>';

Will return:

<h1>Hello!</h1>

You can help the viewable object solves the template file with:

$abc->addTemplatePathSolver(function($obj, $template) {
    $file = '/var/www/project/templates/'.$template.'.php';
    if(file_exists($file))
        return $file;
});

Static rendering

Abc::fragment('tes', [$param1, ...]);

Contributing

Please submit all issues and pull requests to the asgardphp/asgard repository.

License

The Asgard framework is open-sourced software licensed under the MIT license


All versions of templating with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.9
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package asgard/templating contains the following files

Loading the files please wait ....