Download the PHP package fobiaweb/slim-views without Composer
On this page you can find all versions of the php package fobiaweb/slim-views. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fobiaweb/slim-views
More information about fobiaweb/slim-views
Files in fobiaweb/slim-views
Package slim-views
Short Description Smarty and Twig View Parser package for the Slim Framework
License MIT
Informations about the package slim-views
Slim Views
This repository contains custom View classes for the template frameworks listed below. You can use any of these custom View classes by either requiring the appropriate class in your Slim Framework bootstrap file and initialize your Slim application using an instance of the selected View class or using Composer (the recommended way).
Slim Views only officially support the following views listed below.
- Smarty
- Twig
How to Install
using Composer
Create a composer.json file in your project root:
Then run the following composer command:
Smarty
How to use
To use Smarty options do the following:
Twig
How to use
To use Twig options do the following:
In addition to all of this we also have a few helper functions which are included for both view parsers. In order to start using these you can add them to their respective view parser as stated below:
Twig
Smarty
These helpers are listed below.
- urlFor
- siteUrl
- baseUrl
urlFor
Twig
Inside your Twig template you would write:
{{ urlFor('hello', {"name": "Josh", "age": "19"}) }}
You can easily pass variables that are objects or arrays by doing:
<a href="{{ urlFor('hello', {"name": person.name, "age": person.age}) }}">Hello {{ name }}</a>
If you need to specify the appname for the getInstance method in the urlFor functions, set it as the third parameter of the function in your template:
<a href="{{ urlFor('hello', {"name": person.name, "age": person.age}, 'admin') }}">Hello {{ name }}</a>
Smarty
Inside your Smarty template you would write:
{urlFor name="hello" options="name.Josh|age.26"}
or with the new array syntax:
{urlFor name="hello" options=["name" => "Josh", "age" => "26"]}
You can easily pass variables that are arrays as normal or using the (.):
<a href="{urlFor name="hello" options="name.{$person.name}|age.{$person.age}"}">Hello {$name}</a>
If you need to specify the appname for the getInstance method in the urlFor functions, set the appname parameter in your function:
<a href="{urlFor name="hello" appname="admin" options="name.{$person.name}|age.{$person.age}"}">Hello {$name}</a>
siteUrl
Twig
Inside your Twig template you would write:
{{ siteUrl('/about/me') }}
Smarty
Inside your Smarty template you would write:
{siteUrl url='/about/me'}
baseUrl
Twig
Inside your Twig template you would write:
{{ baseUrl() }}
Smarty
Inside your Smarty template you would write:
{baseUrl}
Authors
License
codeguy/develop MIT Public License