Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.
/ jquery-tmpl-php Public archive

A jquery-tmpl-compatible template renderer in PHP.

License

GPL-2.0, MIT licenses found

Licenses found

GPL-2.0
GPL-LICENSE.txt
MIT
MIT-LICENSE.txt
Notifications You must be signed in to change notification settings

abackstrom/jquery-tmpl-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jquery-tmpl-php

An attempt at implementing jquery-tmpl in PHP.

Syntax

jquery-tmpl is implemented by converting template code into valid JavaScript. As such, a number of the features do not translate well to PHP, such as the variety of places you can insert a function into jquery-tmpl template tags. The jqTmpl class supports the following subset of jquery-tmpl syntax:

  • ${foo}, {{= foo}}
  • {{html bar}}
  • {{if foo}}
  • {{else}}, {{else param}}
  • {{! comment}}
  • {{tmpl "selector"}}, ie. {{tmpl "#baz"}}
  • {{each foo}}, {{each(k,v) foo}}

Known unsupported:

  • {{tmpl(foo) "#bar"}} -- data parameter to nested template
  • {{= func()}} -- functions in template tags
  • {{= $item.func()}} -- functions in options parameter to jqTmpl::tmpl()

Dependencies

  • html5lib -- "A Python and PHP implementations of a HTML parser based on the WHATWG HTML5 specification for maximum compatibility with major desktop web browsers."

Optional:

  • PHPUnit -- running tests: make test or phpunit t/jqTmpl.php

Examples

<?php

include 'jqTmpl.class.php';
$t = new jqTmpl;

$html = <<<EOF
<script id="movieTemplate" type="text/x-jquery-tmpl"> 
	{{tmpl "#titleTemplate"}}
	<tr class="detail"><td>Director: \${Director}</td></tr>
</script>

<script id="titleTemplate" type="text/x-jquery-tmpl"> 
	<tr class="title"><td>\${Name}</td></tr>
</script>
EOF;

$t->load_document($html);

$data = array(
	(object)array("Name" => "The Red Violin", "Director" => "Francois Girard"),
	(object)array("Name" => "Eyes Wide Shut", "Director" => "Stanley Kubrick"),
	(object)array("Name" => "The Inheritance", "Director" => "Mauro Bolognini")
);

echo $t->tmpl( '#movieTemplate', $data );

Output (whitespace adjusted):

<tr class="title"><td>The Red Violin</td></tr>
<tr class="detail"><td>Director: Francois Girard</td></tr>

<tr class="title"><td>Eyes Wide Shut</td></tr>
<tr class="detail"><td>Director: Stanley Kubrick</td></tr>

<tr class="title"><td>The Inheritance</td></tr>
<tr class="detail"><td>Director: Mauro Bolognini</td></tr>

See Also

About

A jquery-tmpl-compatible template renderer in PHP.

Resources

License

GPL-2.0, MIT licenses found

Licenses found

GPL-2.0
GPL-LICENSE.txt
MIT
MIT-LICENSE.txt

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages