PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.0
6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / View / View.php
kirki / libraries / framework / View Last commit date
TemplateEngine.php 6 days ago View.php 6 days ago ViewContext.php 6 days ago layout-wrapper.php 6 days ago
View.php
151 lines
1 <?php
2
3 /**
4 * Renderable view value object returned by the view() helper.
5 *
6 * @package Framework
7 * @subpackage View
8 * @since 1.0.0
9 */
10 namespace Kirki\Framework\View;
11
12 \defined('ABSPATH') || exit;
13 use function Kirki\Framework\app;
14 class View
15 {
16 /**
17 * The template name in dot notation.
18 *
19 * @var string
20 *
21 * @since 1.0.0
22 */
23 protected $template;
24 /**
25 * Data passed to the template.
26 *
27 * @var array
28 *
29 * @since 1.0.0
30 */
31 protected $data = [];
32 /**
33 * Whether to wrap the view in the theme layout.
34 *
35 * @var bool
36 *
37 * @since 1.0.0
38 */
39 protected $with_layout = \true;
40 /**
41 * Create a new View instance.
42 *
43 * @param string $template The template name.
44 * @param array $data The template data.
45 *
46 * @return void
47 *
48 * @since 1.0.0
49 */
50 public function __construct(string $template, array $data = [])
51 {
52 $this->template = $template;
53 $this->data = $data;
54 }
55 /**
56 * Disable layout wrapping for this view.
57 *
58 * @return $this
59 *
60 * @since 1.0.0
61 */
62 public function partial()
63 {
64 $this->with_layout = \false;
65 return $this;
66 }
67 /**
68 * Enable or set layout wrapping for this view.
69 *
70 * @param bool $enabled Whether layout wrapping is enabled.
71 *
72 * @return $this
73 *
74 * @since 1.0.0
75 */
76 public function layout($enabled = \true)
77 {
78 $this->with_layout = (bool) $enabled;
79 return $this;
80 }
81 /**
82 * Merge additional data into the view.
83 *
84 * @param array $data The data to merge.
85 *
86 * @return $this
87 *
88 * @since 1.0.0
89 */
90 public function with(array $data)
91 {
92 $this->data = \array_merge($this->data, $data);
93 return $this;
94 }
95 /**
96 * Get the template name.
97 *
98 * @return string
99 *
100 * @since 1.0.0
101 */
102 public function get_template()
103 {
104 return $this->template;
105 }
106 /**
107 * Get the view data.
108 *
109 * @return array
110 *
111 * @since 1.0.0
112 */
113 public function get_data()
114 {
115 return $this->data;
116 }
117 /**
118 * Whether the view uses layout wrapping.
119 *
120 * @return bool
121 *
122 * @since 1.0.0
123 */
124 public function uses_layout()
125 {
126 return $this->with_layout;
127 }
128 /**
129 * Render the view to a string.
130 *
131 * @return string
132 *
133 * @since 1.0.0
134 */
135 public function render()
136 {
137 return app(TemplateEngine::class)->render($this->template, $this->data, $this->with_layout);
138 }
139 /**
140 * Render the view when cast to string.
141 *
142 * @return string
143 *
144 * @since 1.0.0
145 */
146 public function __toString()
147 {
148 return $this->render();
149 }
150 }
151