Deutschland United States United Kingdom
ContentLion - Open Source CMS

Neue Template Engine XTPL

Neue Template Engine XTPL

Ich habe letztens mal eine neue Template Engine XTPL getestet, welche ich auch sehr gut finde. ;)
Im Gegenzug zu Smarty hat diese zwar kleine aber trotzdem mächtige TemplateEngine doch einige Vorteile, die gerade für ein CMS sehr wichtig sind.

Hier mal ein paar aufgelistet:
  • Kurze Ladezeiten dank geringer Last
  • weniger Bugs und mächtiger als die eigene ContentLion Template Engine
  • hat Ähnlichkeiten mit der ContentLion Template Engine, was den Umstieg für Plugin Entwickler einfacher machen würde
  • recht gutes Caching vorhanden
  • Im Gegensatz zu Smarty kann diese Template Engine den Code zurückgeben, was sehr viele Vorteile für Plugin Entwickler mit sich bringt.

Letzteres Kann Smarty auch, einfach die Funktion fetch nutzen ;)

Kannst du vielleicht einfach mal ein paar Beispiele und nen Link posten?

Die Engine von ContentLion ist nicht die beste, da ist Smarty deutlich besser^^

Also die Funktion fetch kannte ich bei Smarty noch nicht, wenn das so sein sollte und diese nicht Performancelastiger ist, wäre der Umstieg auf Smarty vllt. sogar noch besser.

Hier der Beispiel Code:

Quellcode

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
<!-- BEGIN: main -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>example 1</title>
<meta http-equiv="Content-Language" content="en" />
<meta name="GENERATOR" content="Co-Comp Ltd" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<!-- $HeadURL: https://xtpl.svn.sourceforge.net/svnroot/xtpl/trunk/ex1.xtpl $
$Id: ex1.xtpl 16 2007-01-11 03:02:49Z cocomp $ -->
<body>
<p>This is a simple replace test. the text in bold should contain "TEST": <b>{VARIABLE}</b><br />
now a dynamic block test:<br />
	<!-- BEGIN: block1 -->
	this is block 1.<br />
	<!-- END: block1 -->
	<!-- BEGIN: block2 -->
	this is block 2.<br />
	<!-- END: block2 -->
</p>
	<!-- BEGIN: block3#You can comment a block like this -->
	<table border="1">
		<tr>
			<td>id</td>
			<td>{DATA.ID}</td>
		</tr>
		<tr>
			<td>name</td>
			<td>{DATA.NAME#You can comment tags like this}</td>
		</tr>
		<tr>
			<td>age</td>
			<td>{DATA.AGE}</td>
		</tr>
	</table>
	<!-- END: block3#Or comment it here too -->
<p><br />
global variables can be parsed directly into the html without assigns:<br />
$_SERVER['HTTP_HOST']={PHP._SERVER.HTTP_HOST}<br />
$_SERVER['PHP_SELF']={PHP._SERVER.PHP_SELF}<br />
$_SERVER['HTTP_USER_AGENT']={PHP._SERVER.HTTP_USER_AGENT}<br />
etc..<br />
(<span style="color: red;">note</span> that these variables are scanned in the constructor when creating the XTemplate object!
so if you need some variables which you have set after creating the template object, you need to call <b>$xtpl->scan_globals()</b>
before parsing the actual block!</p>
</body>
</html>
<!-- END: main -->


PHP-Quelltext

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
<?php

/**
 * example 1
 * demonstrates basic template functions
 * -simple replaces ( {VARIABLE1}, and {DATA.ID} {DATA.NAME} {DATA.AGE} )
 * -dynamic blocks
 *
 * @package XTemplate_Examples
 * @author Barnabas Debreceni [cranx@users.sourceforge.net]
 * @copyright Barnabas Debreceni 2000-2001
 * @author Jeremy Coates [cocomp@users.sourceforge.net]
 * @copyright Jeremy Coates 2002-2007
 * @see license.txt LGPL / BSD license
 * @link $HeadURL: https://xtpl.svn.sourceforge.net/svnroot/xtpl/trunk/ex1.php $
 * @version $Id: ex1.php 16 2007-01-11 03:02:49Z cocomp $
 */

    include_once('./xtemplate.class.php');

    $xtpl = new XTemplate('ex1.xtpl');

    // simple replace
    $xtpl->assign('VARIABLE''TEST');

    // parse block1
    $xtpl->parse('main.block1');

    // uncomment line below to parse block2
    //$xtpl->parse('main.block2');

    /**
     * you can reference to array keys in the template file the following way:
     * {DATA.ID} or {DATA.NAME}
     * say we have an array from a mysql query with the following fields: ID, NAME, AGE
     */
    $row = array('ID'=>'38',
                'NAME'=>'cocomp',
                 'AGE'=>'33'
             );

    $xtpl->assign('DATA',$row);

    // parse block3
    $xtpl->parse('main.block3');

    $xtpl->parse('main');
    $xtpl->out('main');

?>

Ähnliche Themen