forked from feulf/raintpl3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-all.php
73 lines (56 loc) · 2.15 KB
/
example-all.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
// namespace
use Rain\Tpl;
// include
include "library/Rain/Tpl.php";
// config
$config = array(
"base_url" => null,
"tpl_dir" => "templates/test/",
"cache_dir" => "cache/",
"debug" => true,
"auto_escape" => true,
);
Tpl::configure( $config );
// Add PathReplace plugin
require_once('library/Rain/Tpl/Plugin/PathReplace.php');
Rain\Tpl::register_plugin( new Rain\Tpl\Plugin\PathReplace() );
// set variables
$var = array(
"variable" => "Hello World!",
"version" => "3.0 Alpha",
"menu" => array(
array("name" => "Home", "link" => "index.php", "selected" => true ),
array("name" => "FAQ", "link" => "index.php/FAQ/", "selected" => null ),
array("name" => "Documentation", "link" => "index.php/doc/", "selected" => null )
),
"week" => array( "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ),
"user" => (object) array("name"=>"Rain", "citizen" => "Earth", "race" => "Human" ),
"numbers" => array( 3, 2, 1 ),
"bad_text" => 'Hey this is a malicious XSS <script>alert(1);</script>',
"table" => array( array( "Apple", "1996" ), array( "PC", "1997" ) ),
"title" => "Rain TPL 3 - Easy and Fast template engine",
"copyright" => "Copyright 2006 - 2012 Rain TPL<br>Project By Rain Team",
);
// add a tag
Tpl::register_tag( "({@.*?@})", // preg split
"{@(.*?)@}", // preg match
function( $params ){ // function called by the tag
$value = $params[1][0];
return "Translate: <b>$value</b>";
}
);
// add a tag
Tpl::register_tag( "({%.*?%})", // preg split
"{%(.*?)(?:\|(.*?))%}", // preg match
function( $params ){ // function called by the tag
$value = $params[1][0];
$value2 = $params[2][0];
return "Translate: <b>$value</b> in <b>$value2</b>";
}
);
// draw
$tpl = new Tpl;
$tpl->assign( $var );
echo $tpl->draw( "test" );
?>