PluginProbe
Assistant – Every Day Productivity Apps / trunk
Assistant – Every Day Productivity Apps vtrunk
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 trunk, at backend/src/System/View.php

77 lines 1.3 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 /**
25 * @param string $template_dir
26 *
27 * @return $this
28 */
29 public function set_template_dir( $template_dir ) {
30 $this->template_dir = $template_dir;
31
32 return $this;
33 }
34
35 /**
36 * @return string path
37 */
38 public function get_template_dir() {
39 return $this->template_dir;
40 }
41
42
43 /**
44 * Render template to string
45 *
46 * @param $template_name
47 * @param array $data
48 *
49 * @return false|string
50 */
51 public function render_to_string( $template_name, array $data = [] ) {
52
53 error_reporting( E_ALL );
54
55 $path = sprintf( '%s/%s.php', $this->template_dir, $template_name );
56
57 ob_start();
58
59 extract( $data );
60
61 include( $path );
62
63 $output = ob_get_clean();
64 return $output;
65 }
66
67 /**
68 * Render template to echo
69 *
70 * @param $template_name
71 * @param array $data
72 */
73 public function render( $template_name, array $data = [] ) {
74 echo $this->render_to_string( $template_name, $data );
75 }
76 }
77