1 <?php
2 /**
3 * Import.php
4 *
5 * @author Elvyrra SAS
6 * @license http://rem.mit-license.org/ MIT
7 */
8
9 namespace Hawk\View\Plugins;
10
11 /**
12 * This class is used to import a view file in another view.
13 * Importation will transfer all the view context (variables) in the imported view
14 * Exemple :
15 * <code>{import file="{$filename}"}</code>
16 *
17 * @package View\Plugins
18 */
19 class Import extends \Hawk\ViewPlugin{
20 /**
21 * The id of the form to display
22 *
23 * @var string
24 */
25 public $file;
26
27 /**
28 * Import the file
29 */
30 public function display(){
31 if($this->file{0} == '/') {
32 // Absolute path
33 $basedir = ROOT_DIR;
34 $this->file = preg_replace('#^' . ROOT_DIR . '#', '', $this->file);
35 }
36 else{
37 // Path relative to the view that included the file
38 $basedir = dirname(realpath($this->viewFile));
39 }
40
41 return \Hawk\View::make($basedir . '/' . $this->file, $this->viewData);
42 }
43 }