You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/1-essentials/02-views.md
+61Lines changed: 61 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -639,6 +639,67 @@ Don't forget to run `composer up` after making changes to your composer.json fil
639
639
640
640
Note that view files themselves don't need a namespace; this namespace is only here to tell Tempest that `views/` is a directory it should scan. If you want to add a class in the `Views` namespace (like, for example, a [custom view object](/2.x/essentials/views#using-dedicated-view-objects)), then that is possible as well.
641
641
642
+
## Tempest View as a standalone engine
643
+
644
+
Tempest View is also designed to be used as a standalone engine in whatever PHP project you want. Start by requiring `tempest/view`:
645
+
646
+
```sh
647
+
composer require tempest/view
648
+
```
649
+
650
+
As a bare minimum setup, you can create an instance of the renderer by calling `TempestViewRenderer::make()`:
If, however, you want view component support, you will need to provide a `ViewConfig` object as well:
662
+
663
+
```php
664
+
use Tempest\View\Renderers\TempestViewRenderer;
665
+
use Tempest\View\ViewConfig;
666
+
667
+
$config = new ViewConfig()->addViewComponents(
668
+
__DIR__ . '/components/x-base.view.php',
669
+
__DIR__ . '/components/x-footer.view.php',
670
+
__DIR__ . '/components/x-header.view.php',
671
+
);
672
+
673
+
$renderer = TempestViewRenderer::make($config);
674
+
```
675
+
676
+
If you want to rely on Tempest's discovery to find view components, you can boot a minimal version of Tempest, and resolve the view renderer from the container:
You can choose whichever way you prefer. Chances are that, if you use the minimal setup without booting Tempest, you'll want to add a custom view component loader. That's up to you to implement then.
690
+
691
+
### A note on caching
692
+
693
+
When you're using the minimal setup, view caching can be enabled by passing in a `$cache` paremeter into `TempestViewRenderer::make()`:
694
+
695
+
```php
696
+
$renderer = TempestViewRenderer::make(
697
+
cache: true,
698
+
);
699
+
```
700
+
701
+
It's recommended to turn view caching on in production environments. To clear the view cache, you'll have to manually delete the cache directory, which is located at `./vendor/tempest/view/.tempest/cache`.
702
+
642
703
## Using other engines
643
704
644
705
While Tempest View is simple to use, it currently lacks tooling support from editors and IDEs. You may also simply prefer other templating engines. For these reasons, you may use any other engine of your choice.
0 commit comments