|
1 | 1 | # Custom Views |
2 | 2 |
|
3 | | -The Slim Framework provides a default View class that uses PHP template files by default. This folder includes custom View classes that you may use with alternative template libraries, such as [Twig](http://www.twig-project.org/), [Smarty](http://www.smarty.net/), or [Mustache](http://mustache.github.com/). |
| 3 | +The Slim Framework provides a default view class that uses PHP template files. This folder includes custom view classes |
| 4 | +that you may use with third-party template libraries, such as [Twig](http://www.twig-project.org/), |
| 5 | +[Smarty](http://www.smarty.net/), or [Mustache](http://mustache.github.com/). |
4 | 6 |
|
5 | | -## TwigView |
| 7 | +## Twig |
6 | 8 |
|
7 | | -The `TwigView` custom View class provides support for the [Twig](http://twig.sensiolabs.org/) template library. You can use the TwigView custom View in your Slim application like this: |
| 9 | +The `\Slim\Extras\Views\Twig` custom view class provides support for the [Twig](http://twig.sensiolabs.org/) template |
| 10 | +library. You can use the Twig custom view in your Slim Framework application like this: |
8 | 11 |
|
9 | 12 | <?php |
10 | | - require 'slim/Slim.php'; |
11 | | - require 'views/TwigView.php'; |
12 | | - $app = new Slim(array( |
13 | | - 'view' => 'TwigView' |
| 13 | + $app = new \Slim\Slim(array( |
| 14 | + 'view' => new \Slim\Extras\Views\Twig() |
14 | 15 | )); |
15 | | - //Insert your application routes here |
16 | | - $app->run(); |
17 | | - ?> |
18 | 16 |
|
19 | | -You will need to configure the `TwigView::$twigOptions` and `TwigView::$twigDirectory` class variables before using the TwigView class in your application. These variables can be found at the top of the `views/TwigView.php` class definition. |
| 17 | +You will need to configure the Twig view's public `$twigOptions` and `$twigDirectory` properties. The `$twigDirectory` |
| 18 | +property is the relative or absolute path to the Twig library. The `$twigOptions` property is an array of Twig settings. |
20 | 19 |
|
21 | | -## MustacheView |
| 20 | +## Mustache |
22 | 21 |
|
23 | | -The `MustacheView` custom View class provides support for the [Mustache template language](http://mustache.github.com/) and the [Mustache.php library](github.com/bobthecow/mustache.php). You can use the MustacheView custom View in your Slim application like this: |
| 22 | +The `\Slim\Extras\Views\Mustache` custom view class provides support for the |
| 23 | +[Mustache template language](http://mustache.github.com/) and the [Mustache.php library](github.com/bobthecow/mustache.php). |
| 24 | +You can use the Mustache custom view in your Slim Framework application like this: |
24 | 25 |
|
25 | 26 | <?php |
26 | | - require 'slim/Slim.php'; |
27 | | - require 'views/MustacheView.php'; |
28 | | - MustacheView::$mustacheDirectory = 'path/to/mustacheDirectory/'; |
29 | | - $app = new Slim(array( |
30 | | - 'view' => 'MustacheView' |
| 27 | + \Slim\Extras\Views\Mustache::$mustacheDirectory = 'path/to/mustacheDirectory/'; |
| 28 | + $app = new \Slim\Slim(array( |
| 29 | + 'view' => new \Slim\Extras\Views\Mustache() |
31 | 30 | )); |
32 | | - //Insert your application routes here |
33 | | - $app->run(); |
34 | | - ?> |
35 | 31 |
|
36 | | -Before you can use the MustacheView class, you will need to set `MustacheView::$mustacheDirectory`. This property should be the relative or absolute path to the directory containing the `Mustache.php` library. |
| 32 | +Before you can use the Mustache view class, you must set its static public `$mustacheDirectory` property; this is the |
| 33 | +relative or absolute path to the Mustache library. |
37 | 34 |
|
38 | 35 | ## SmartyView |
39 | 36 |
|
40 | | -The `SmartyView` custom View class provides support for the [Smarty](http://www.smarty.net/) template library. You can use the SmartyView custom View in your Slim application like this: |
| 37 | +The `\Slim\Extras\Views\Smarty` custom view class provides support for the [Smarty](http://www.smarty.net/) template |
| 38 | +library. You can use the Smarty custom view in your Slim Framework application like this: |
41 | 39 |
|
42 | 40 | <?php |
43 | | - require 'slim/Slim.php'; |
44 | | - require 'views/SmartyView.php'; |
45 | | - $app = new Slim(array( |
46 | | - 'view' => 'SmartyView' |
| 41 | + $app = new \Slim\Slim(array( |
| 42 | + 'view' => new \Slim\Extras\Views\Smarty() |
47 | 43 | )); |
48 | | - //Insert your application routes here |
49 | | - $app->run(); |
50 | | - ?> |
51 | 44 |
|
52 | | -You will need to configure the `SmartyView::$smartyDirectory`, `SmartyView::$smartyCompileDirectory` , `SmartyView::$smartyCacheDirectory` and optionally `SmartyView::$smartyTemplatesDirectory`, class variables before using the SmartyView class in your application. These variables can be found at the top of the `views/SmartyView.php` class definition. |
| 45 | +You must configure the Smarty view's public static `$smartyDirectory`, `$smartyCompileDirectory` , `$smartyCacheDirectory` |
| 46 | +and optionally `$smartyTemplatesDirectory` properties before using the Smarty view class in your application. These |
| 47 | +properties are at the top of the `Views/Smarty.php` class definition. |
53 | 48 |
|
54 | | -## BlitzView |
| 49 | +## Blitz |
55 | 50 |
|
56 | | -The `BlitzView` custom View class provides support for the Blitz templating system for PHP. Blitz is written as C and compiled to a PHP extension. Which means it is FAST. You can learn more about Blitz at <http://alexeyrybak.com/blitz/blitz_en.html>. You can use the BlitzView custom View in your Slim application like this: |
| 51 | +The `\Slim\Extras\Views\Blitz` custom view class provides support for the Blitz templating system. Blitz is written |
| 52 | +as C and is compiled to a PHP extension. This means it is FAST. You can learn more about Blitz at |
| 53 | +<http://alexeyrybak.com/blitz/blitz_en.html>. You can use the Blitz custom view in your Slim Framework application like this: |
57 | 54 |
|
58 | 55 | <?php |
59 | | - require 'slim/Slim.php'; |
60 | | - require 'views/BlitzView.php'; |
61 | | - $app = new Slim(array( |
62 | | - 'view' => 'BlitzView' |
| 56 | + $app = new \Slim\Slim(array( |
| 57 | + 'view' => new \Slim\Extras\Views\Blitz() |
63 | 58 | )); |
64 | | - //Insert your application routes here |
65 | | - $app->run(); |
66 | | - ?> |
67 | | - |
68 | | -Place your Blitz template files in the designated templates directory. |
69 | 59 |
|
70 | 60 | ## HaangaView |
71 | 61 |
|
72 | | -The `HaangaView` custom View class provides support for the Haanga templating system for PHP. Refer to the `views/HaangaView.php` file for further documentation. |
| 62 | +The `\Slim\Extras\Views\Haanga` custom view class provides support for the Haanga templating system. Refer to |
| 63 | +the `Views/Haanga.php` file for further documentation. |
73 | 64 |
|
74 | 65 | <?php |
75 | | - require 'slim/Slim.php'; |
76 | | - require_once 'views/HaangaView.php'; |
77 | | - $app = new Slim(array( |
78 | | - 'view' => new HaangaView('/path/to/Haanga/dir', '/path/to/templates/dir', '/path/to/compiled/dir') |
| 66 | + $app = new \Slim\Slim(array( |
| 67 | + 'view' => new \Slim\Extras\Views\Haanga( |
| 68 | + '/path/to/Haanga/dir', |
| 69 | + '/path/to/templates/dir', |
| 70 | + '/path/to/compiled/dir' |
| 71 | + ) |
79 | 72 | )); |
80 | | - //Insert your application routes here |
81 | | - $app->run(); |
82 | | - ?> |
83 | 73 |
|
84 | | -## H2oView |
| 74 | +## H2o |
85 | 75 |
|
86 | | -The `H2oView` custom View class provides support for the [H2o templating system](http://www.h2o-template.org) for PHP. You can use the H2oView custom View in your application like this: |
| 76 | +The `H2o` custom view class provides support for the [H2o templating system](http://www.h2o-template.org). You can |
| 77 | +use the H2o custom view in your Slim Framework application like this: |
87 | 78 |
|
88 | 79 | <?php |
89 | | - require 'slim/Slim.php'; |
90 | | - require 'views/H2oView.php'; |
91 | | - |
92 | | - H2oView::$h2o_directory = './h2o/'; |
93 | | - |
94 | | - $app = new Slim(array('view' => new H2oView)); |
95 | | - // Insert your application routes here |
96 | | - $app->run(); |
97 | | - ?> |
| 80 | + \Slim\Extras\Views\H2o::$h2o_directory = './h2o/'; |
| 81 | + $app = new \Slim\Slim(array( |
| 82 | + 'view' => new \Slim\Extras\Views\H2oView() |
| 83 | + )); |
98 | 84 |
|
99 | | -Refer to the `Views/H2oView.php` file for further documentation. |
| 85 | +Refer to the `Views/H2o.php` file for further documentation. |
100 | 86 |
|
0 commit comments