ProductPromotion
Logo

PHP

made by https://0x3d.site

GitHub - slimphp/Slim-Views: Slim Framework 2 custom views
Slim Framework 2 custom views. Contribute to slimphp/Slim-Views development by creating an account on GitHub.
Visit Site

GitHub - slimphp/Slim-Views: Slim Framework 2 custom views

GitHub - slimphp/Slim-Views: Slim Framework 2 custom 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

Install in your project by running the following composer command:

$ php composer require slim/views

Smarty

How to use

<?php
require 'vendor/autoload.php';

$app = new \Slim\Slim(array(
    'view' => new \Slim\Views\Smarty()
));

To use Smarty options do the following:

$view = $app->view();
$view->parserDirectory = dirname(__FILE__) . 'smarty';
$view->parserCompileDirectory = dirname(__FILE__) . '/compiled';
$view->parserCacheDirectory = dirname(__FILE__) . '/cache';

Twig

How to use

<?php
require 'vendor/autoload.php';

$app = new \Slim\Slim(array(
    'view' => new \Slim\Views\Twig()
));

To use Twig options do the following:

$view = $app->view();
$view->parserOptions = array(
    'debug' => true,
    'cache' => dirname(__FILE__) . '/cache'
);

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

$view->parserExtensions = array(
    new \Slim\Views\TwigExtension(),
);

Smarty

$view->parserExtensions = array(
    dirname(__FILE__) . '/vendor/slim/views/Slim/Views/SmartyPlugins',
);

These helpers are listed below.

  • urlFor
  • siteUrl
  • baseUrl
  • currentUrl

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}

currentUrl

Twig

Inside your Twig template you would write:

{{ currentUrl() }}

Smarty

Inside your Smarty template you would write:

{currentUrl}

Authors

Josh Lockhart

Andrew Smith

License

MIT Public License

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory