PluginProbe
Assistant – Every Day Productivity Apps / 0.3.1
Assistant – Every Day Productivity Apps v0.3.1
1.5.5 trunk 0.1.0 0.2.0 0.2.1 0.2.2 0.3.0 0.3.1 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.6.0 0.7.0 0.7.0.2 0.7.0.3 0.7.0.4 0.7.0.5 0.7.0.6 0.7.0.7 0.7.0.8 0.7.0.9 0.7.1 1.0 All 71 releases
assistant / backend / src / System / View.php

View.php in Assistant – Every Day Productivity Apps 0.3.1, at backend/src/System/View.php

71 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace FL\Assistant\System;
5
6 /**
7 * Class View
8 * @package FL\Assistant\Util
9 *
10 * @phpcs:disable WordPress.PHP.DontExtract.extract_extract
11 */
12 class View {
13
14 /**
15 * @var string path to template dir
16 */
17 protected $template_dir;
18
19 public function __construct( $template_dir ) {
20 $this->template_dir = $template_dir;
21 }
22
23 /**
24 * @param string $template_dir
25 *
26 * @return $this
27 */
28 public function set_template_dir( $template_dir ) {
29 $this->template_dir = $template_dir;
30
31 return $this;
32 }
33
34 /**
35 * @return string path
36 */
37 public function get_template_dir() {
38 return $this->template_dir;
39 }
40
41
42 /**
43 * Render template to string
44 *
45 * @param $template_name
46 * @param array $data
47 *
48 * @return false|string
49 */
50 public function render_to_string( $template_name, array $data = [] ) {
51 $path = sprintf( '%s/%s.php', $this->template_dir, $template_name );
52
53 ob_start();
54 extract( $data );
55 include( $path );
56 $output = ob_get_clean();
57
58 return $output;
59 }
60
61 /**
62 * Render template to echo
63 *
64 * @param $template_name
65 * @param array $data
66 */
67 public function render( $template_name, array $data = [] ) {
68 echo $this->render_to_string( $template_name, $data );
69 }
70 }
71