This repository was archived by the owner on Jan 31, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Layout
2
+
3
+ The ` Layout ` helper is used to get and set the template for the layout or to
4
+ retrieving the root view model.
5
+
6
+ ## Basic Usage
7
+
8
+ ### Change the Layout Template
9
+
10
+ If you're running a zend-mvc application then the layout template is set in the
11
+ configuration for the [ ` ViewManager ` ] ( https://docs.zendframework.com/zend-mvc/services/#viewmanager ) .
12
+
13
+ To change the layout template within a view script, call:
14
+
15
+ ``` php
16
+ $this->layout('layout/backend');
17
+ ```
18
+
19
+ Or use the ` setTemplate ` method:
20
+
21
+ ``` php
22
+ $this->layout()->setTemplate('layout/backend');
23
+ ```
24
+
25
+ ### Set View Variable on Layout Model
26
+
27
+ The ` Layout ` helper can also retrieve the view model for the layout (root):
28
+
29
+ ``` php
30
+ /** @var \Zend\View\Model\ViewModel $rootViewModel */
31
+ $rootViewModel = $this->layout();
32
+ ```
33
+
34
+ This offers the possibility to set variables for the layout script.
35
+
36
+ #### Set a Single Variable
37
+
38
+ ``` php
39
+ $this->layout()->setVariable('infoText', 'Some text for later');
40
+ ```
41
+
42
+ Use in your layout script:
43
+
44
+ ``` php
45
+ if (isset($infoText)) {
46
+ echo $infoText;
47
+ }
48
+ ```
49
+
50
+ #### Set a Set of Variables
51
+
52
+ ``` php
53
+ $this->layout()->setVariables([
54
+ 'headerText' => '…',
55
+ 'footerText' => '…',
56
+ ]);
57
+ ```
58
+
59
+ More informations related to view models can be found in the
60
+ [ quick start] ( https://docs.zendframework.com/zend-view/quick-start/ ) .
You can’t perform that action at this time.
0 commit comments