FyreView is a free, open-source template rendering library for PHP.

Related tags

Templating FyreView
Overview

FyreView

FyreView is a free, template rendering library for PHP.

Table Of Contents

Installation

Using Composer

composer require fyre/view

In PHP:

use Fyre\View\View;

Methods

$view = new View();

Element

Render an element.

  • $file is a string representing the element file.
  • $data is an array containing data to pass to the element, and will default to [].
echo $view->element($file, $data);

Element files must end in the extension .php, and must exist in an "elements" folder in one of the defined paths.

Get Data

Get the view data.

$data = $view->getData();

Get Layout

Get the layout.

$layout = $view->getLayout();

Load Helper

Load a Helper.

  • $name is a string representing the helper name.
  • $options is an array containing helper options.
$helper = $view->loadHelper($name, $options);

Render

Render a template.

  • $file is a string representing the template file.
echo $view->render($file);

Templates files must end in the extension .php, and must exist in one of the defined paths.

Set Data

Set view data.

  • $data is an array containing data to pass to the template.
$view->setData($data);

Set Layout

Set the layout.

  • $layout is a string representing the layout file.
$view->setLayout($layout);

Layout files must end in the extension .php, and must exist in a "layouts" folder in one of the defined paths.

Layouts

You can use layouts when rendering views by placing a default.php file in a layouts folder of one of the defined paths. You can create multiple layouts, and specify the layout to use with the setLayout method above.

The rendered content is passed to the layout file via the content method of $this. Any other defined data is also passed to the layout.

$this->content();

Paths

Layouts, templates and elements are loaded by searching available paths.

Add Path

Add a path for loading templates.

  • $path is a string representing the path.
View::addPath($path);

Helper Registry

use Fyre\View\HelperRegistry;

Add Namespace

Add a namespace for automatically loading helpers.

  • $namespace is a string representing the namespace.
HelperRegistry::addNamespace($namespace);

Clear

Clear all namespaces and helpers.

HelperRegistry::clear();

Find

Find a helper class.

  • $name is a string representing the helper name.
$className = HelperRegistry::find($name);

Load

Load a helper.

  • $name is a string representing the helper name.
  • $view is a View.
  • $options is an array containing helper options.
$helper = HelperRegistry::load($name, $view, $options);

Helpers

Helpers can be used inside of templates or elements using the class name as a property of $this.

$helper = $this->MyHelper;

Alternatively, you can load a helper with configuration options using the loadHelper method of the View.

Custom helpers can be created by extending \Fyre\View\Helper, suffixing the class name with "Helper", and ensuring the __construct method accepts View as the argument.

Get Config

Get the configuration options.

$config = $helper->getConfig();

Get View

Get the View.

$view = $helper->getView();

CSP

The CSP helper allows an easy way to generate nonces, and automatically add them to your CSP policies.

Script Nonce

Generate a script nonce.

$nonce = $this->CSP->scriptNonce();

Style Nonce

Generate a style nonce.

$nonce = $this->CSP->styleNonce();

Form

The form helper provides a convenient wrapper for FormBuilder methods, and includes the following additional methods:

Csrf

Render a CSRF token input element.

$input = $this->Form->csrf();

Format

The format helper provides a convenient wrapper for Formatter methods.

Url

The URL helper provides methods for generating Router links.

Link

Generate an anchor link for a destination.

  • $content is a string representing the link content.
  • $destination is a string or array containing the destination.
  • $options is an array containing options.
    • escape is a boolean indicating whether to escape the link content, and will default to true.
    • fullBase is a boolean indicating whether to use the full base URI, and will default to false.
$link = $this->Url->link($content, $destination, $options);

To

Generate a url for a destination.

  • $destination is a string or array containing the destination.
  • $options is an array containing options.
    • fullBase is a boolean indicating whether to use the full base URI, and will default to false.
$url = $this->Url->to($destination, $options);
You might also like...
A complete and fully-functional implementation of the Jade template language for PHP

Tale Jade for PHP Finally a fully-functional, complete and clean port of the Jade language to PHP — Abraham Lincoln The Tale Jade Template Engine brin

A ready-to-use Model View Controller template in PHP

PHP-MVC-Template A ready-to-use Model View Controller template in PHP Use this repo as a template! (Or clone it) Start to configure your MVC file Afte

Provides a GitHub repository template for a PHP package, using GitHub actions.

php-package-template Installation 💡 This is a great place for showing how to install the package, see below: Run $ composer require ergebnis/php-pack

⚡️ Simple and fastly template engine for PHP

EasyTpl ⚡️ Simple and fastly template engine for PHP Features It's simple, lightweight and fastly. No learning costs, syntax like PHP template It is s

Twig Template Engine to Phalcon PHP

Twig Template Engine to Phalcon PHP

Liquid template engine for PHP

Liquid is a PHP port of the Liquid template engine for Ruby, which was written by Tobias Lutke. Although there are many other templating engines for PHP, including Smarty (from which Liquid was partially inspired)

Foil brings all the flexibility and power of modern template engines to native PHP templates

Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simple, clean and concise templates with nothing more than PHP.

A lightweight template parser used by PyroCMS.

Lex Lex is a lightweight template parser. Lex is released under the MIT License and is Copyrighted 2011 - 2014 PyroCMS Team. Change Log 2.3.2 Convert

Laravel package template

REPLACE Simple and flexible package template. Usage Replace all occurances of REPLACE (case sensitive) with the name of the package namespace. E.g. th

Releases(v4.0.1)
Owner
Elusive
Just a guy who likes codin' stuff.
Elusive
A template abstraction prototype for PHP template engines

Schranz Templating A template abstraction prototype for PHP template engines. This project should help to find a way for a general Template Render Int

Schranz Templating 16 Dec 7, 2022
The free-to-use template for your Imagehost-website made with PHP, HTML and CSS!

The free-to-use template for your Imagehost-website made with PHP, HTML and CSS! Some information before we start This repo is only code related, to a

Ilian 6 Jul 22, 2022
The free-to-use template for your Imagehost-website made with PHP, HTML and CSS!

The free-to-use template for your Imagehost-website made with PHP, HTML and CSS! Some information before we start This repo is only code related, to a

Ilian 6 Jul 22, 2022
PHP template engine for native PHP templates

FOIL PHP template engine, for PHP templates. Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simpl

Foil PHP 167 Dec 3, 2022
A PHP project template with PHP 8.1, Laminas Framework and Doctrine

A PHP project template with PHP 8.1, Laminas Framework and Doctrine

Henrik Thesing 3 Mar 8, 2022
Twig, the flexible, fast, and secure template language for PHP

Twig, the flexible, fast, and secure template language for PHP Twig is a template language for PHP, released under the new BSD license (code and docum

Twig 7.7k Jan 1, 2023
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.

Smarty 3 template engine smarty.net Documentation For documentation see www.smarty.net/docs/en/ Requirements Smarty can be run with PHP 5.2 to PHP 7.4

Smarty PHP Template Engine 2.1k Jan 1, 2023
Native PHP template system

Plates Plates is a native PHP template system that's fast, easy to use and easy to extend. It's inspired by the excellent Twig template engine and str

The League of Extraordinary Packages 1.3k Jan 7, 2023
☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites.

Latte: amazing template engine for PHP Introduction Latte is a template engine for PHP which eases your work and ensures the output is protected again

Nette Foundation 898 Dec 25, 2022
View template engine of PHP extracted from Laravel

Blade 【简体中文】 This is a view templating engine which is extracted from Laravel. It's independent without relying on Laravel's Container or any others.

刘小乐 143 Dec 13, 2022