-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComponent.php
57 lines (49 loc) · 1.4 KB
/
Component.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace Twig\Blank;
/**
* Slim - a micro PHP 5 framework
*
* @package TwigBlank
*
*/
class Component extends \Twig_Extension
{
public function getName()
{
return 'twig_components';
}
public function getFunctions()
{
return array(
'component' => new \Twig_Function_Method($this, 'get_component', array('is_safe' => array('html'),'needs_environment' => true)),
'component_exist' => new \Twig_Function_Method($this, 'component_exist', array('is_safe' => array('html'),'needs_environment' => true))
);
}
public function get_component(\Twig_Environment $twig, $name, $data)
{
$path = explode( '/',$name);
if( count($path) > 1 ){
$html = $twig->render( $name.'.html.twig', $data );
}else {
$html = $twig->render('components/'.$name.'.html.twig', $data );
}
return $html;
}
public function component_exist(\Twig_Environment $twig, $name)
{
$path = explode( '/',$name);
if( count($path) > 1 ){
if( file_exists('App/views/' . $name . '.html.twig') ) {
return true;
} else {
return false;
}
}else {
if( file_exists('components/'.$name.'.html.twig') ) {
return true;
} else {
return false;
}
}
}
}