Please help support Savant; you can donate, or click on a sponsor.
|
Savant3 (3.0.0)
Savant3 is a template system for PHP5. It sports all of the features of Savant2, but with a modified default plugin set and a modified filter system. In addition, it runs cleanly under E_ALL and E_STRICT error reporting.
API documentation is here!
You can use PEAR to install the most recent release (version 3.0.0 on 2006-01-01):
bash-2.05$ pear install http://phpsavant.com/Savant3-3.0.0.tgz
- This is the first stable release.
- Plugin htmlAttribs no longer renders a key when its value is null.
- Removed the deprecated _() method; use eprint() instead.
- Added "avoidance" code to __call() and eprint() so they don't use call_user_func_array() as much; thanks to Andreas Korthaus for profiling the code and finding out how slow call_user_func_array() can be.
- Added setAutoload() method to tell Savant whether or not to use __autoload() when checking class_exists() on plugins, filters, etc. All class_exists() calls now honor that setting (which is false by default). Thanks to Felix-Gabriel Gangu, David Mytton, and Ian Eure for their discovery and discussion of the problem.
- Fixed bugs in stream support due to improper strpos() param order. Thanks, Antti Holvikari.
Of note, there is a new Savant3_Plugin_Form package; the form generator has grown large enough at this point to warrant its own separate versioning.
You can use PEAR to install the most recent development release (version 0.2.1 as of 2005-09-22):
bash-2.05$ pear install http://phpsavant.com/Savant3_Plugin_Form-0.2.1.tgz
We'll write up separate documentation for it as well.
This site powered by YaWiki 0.22 beta.
Copyright © 2003-2010, Paul M. Jones.
pmjones [AT] ciaweb [DOT] net
2006-08-24 09:19:38 (1172)
Hi rfaraj -- ah yes, I can see that I failed to update the narrative to go
along with the release. I have done so now. Thanks for pointing it out!
|
pmjones [AT] ciaweb [DOT] net
2006-08-24 09:17:05 (1171)
Hi -- Savant3 is stable and production ready, and has been January 1, 2006.
:-)
|
rfaraj [AT] guildquality [DOT] com
2006-08-23 18:04:28 (1170)
Any idea when Savant 3 will come out of 'Development' status and into
production ready?
thanks!
|
foddermk [AT] gmail [DOT] com
2006-08-14 12:30:29 (1166)
Pardon me if this has been explained somewhere else but I just couldn't
find it. Why was the $this->_() function dropped in favour of
$this->eprint()?
|
brandonprudent [AT] yahoo [DOT] com
2006-08-09 00:53:48 (1165)
Note that the seemingly innocent
<?php
require( 'Savant3.php' );
$template =& new Savant3();
$template->assign( 'title', 'Poopy pants' );
print $template->fetch( '/publicwww/test/some_template.tpl.php' );
?>
Freaks out without an '$template->addPath( 'template', '/' );'.
I had to read into the code to figure this out, wasted like 20 minutes ...
hope it helps :)
|
fpoeydomenge-nospam [AT] free [DOT] fr
2006-01-05 06:58:24 (1075)
Hi Paul !
There is no need to unconditionally include abstract classes from
Savant3.php, because they are not mandatory (I can use Savant3 without
them), and what's more, they need to be extended to be used. So the
following 2 lines should go in the class extending Savant3_Filter or
Savant3_Plugin, don't you think ?
/**
* Always have these classes available.
*/
include_once dirname(__FILE__) . '/Savant3/Filter.php';
include_once dirname(__FILE__) . '/Savant3/Plugin.php';
Fred.
|
code [AT] 2trs [DOT] com
2005-12-18 22:44:53 (1067)
Newbie needs direction.
Reseller hosting environment. I only know php, html, css. No experience
with pear, perl, java, objects, etc. Will be using SQLite, Savant3, php,
css.
I've manually downloaded Savant3.0 beta2, unzipped it, and moved the folder
into my www root. I've found it only works if my .php and tpl.php files are
within the same folder as Savant3.php, which must be within the Savant3
folder.
Where should I put the Savant3 folder? Does it go outside www root for
security?
How do I get around having to include the full path of Savant3.php in
require_once() ?
Am I supposed to put a command in htaccess???
I know nothing about php.ini (I hear about it everywhere, but I've yet to
discover anything about it)
ps. I love the idea about putting different headings and footer in
sections, suggested on 8/22/05
Thanks in Adv.
-Jupiter
|
rok [DOT] bermez [AT] zavod-zviti [DOT] si
2005-11-25 06:28:09 (1064)
inserting:
if(file_exists($file)&& is_readable($file))return $file;
before return false; into function findFile solves the issue.
|
rok [DOT] bermez [AT] zavod-zviti [DOT] si
2005-11-25 06:04:10 (1063)
Savant3 doesent seem to work with anything symlink related.
Example:
'templates/template.tpl'
it will fail if either the directory 'templates' is a symplink pointing to
somewhere else or if template.tpl points somewhere else.
|
anonymous
2005-11-23 06:35:38 (1060)
Hey!
This project is quite a long time in beta!
When will this be released as final?
Are there any benchmark comparisons between Smarty and Savant 3?
|
anonymous
2005-09-23 22:28:03 (973)
I started playing with Savant3 beta 2 today (hadn't tried Savant2), and
when creating a simple test template, I got the following as a result of
trying to display my template:
template error, examine fetch() result
Which unfortunately, wasn't helpful in the least. I ran a var_dump on the
results of the fetch, but that didn't help very much either. It informed
me of the error type: ERR_TEMPLATE which held that generic error text.
The only error info that was stored in the object was: array('template' =>
'index.tpl.php') I suspected it had something to do with my template_path,
but had to backtrace my way through to code and insert my own useful
debugging information before I could pinpoint the problem. It ended up
that the template file was in a subdirectory, but it would've been much
easier if the error codes would inidicate suche. For example, if it had
simply said:
Error: Could not find template index.tpl.php in the template_paths:
display_template_paths...
That would've been much more helpful.
In the function template():
// find the template source.
$file = $this->findFile('template', $tpl);
if (! $file) {
return $this->error(
'ERR_TEMPLATE',
array('message' => 'Could not find template ' . $tpl . ' in
template_path ' . var_dump($this->template_path)
)
);
}
And then, instead of just printing the generic error_text() when printing
out the error, print the specific error message would save some time.
|
pmjones [AT] ciaweb [DOT] net
2005-09-14 13:47:53 (969)
Hi Örjan --
One quick followup to your excellent example: the Savant eprint() method
automatically escapes output. For the Smarty folks to get the
eprint()-like output escaping, they would have to do this:
{foobar->meth1 p1="foo" p2=$bar assign="output"}
the output was {$output|escape:"html"}
In addition, if you decided that you wanted a different default escaping,
you only change one config setting with Savant3 (the 'escape' config) and
the new escaping would apply everywhere automatically.
With Smarty, unless you had set up your own custom escape routine, you
would need to go through all your templates and modify your output calls.
|
o [DOT] persson [AT] gmail [DOT] com
2005-09-14 08:03:15 (968)
Not everyone wants the template engine to handle caching. And by using
Savant, the overhead is pretty small and you would probably not gain
anything in speed at all by using caching in the templates. Why Smarty need
to cache the templates is because it parsers the templates.
What you probably wants to do is to add caching functionality in your PHP
script/classes, not in your template. Cause your template shouldn't do much
calculations, that's up to your script! Several large database results can
easily be cached, and you only need to fetch the data which has become
invalid.
You would probably need to cache this anyway if you were to use Smarty and
wanted it fast. I use Cache_Lite, but I'm sure there's more great libraries
out there you could use (memcache, APC functionality etc).
If you still want this functionality -- it's trivial to add it to Savant by
yourself. You can easily add your own compiler/pre-processor to Savant.
And about Smarty's easy syntax, I find it really hard to code in Smarty
since I always have to lookup "hmm, how did I do a for-loop in Smarty". And
my real-life experience says that a user never wants to change the
PHP-script, they only change the HTML. Just tell them not to touch the
PHP-parts. And if they know PHP, that's great! Then they can do whatever
they want (not limited to the functionality Smarty offers). I believe tools
like Dreamweaver etc don't evern touch the PHP code, which makes it perfect
in that sense.
Seriously, which of these tiny examples do you prefer for readability (I
hope I understood Smarty correct. You could also use short-tags to easier
print stuff.)?
Smarty:
{foobar->meth1 p1="foo" p2=$bar assign="output"}
the output was {$output)
PHP:
<?php $output = $foobar->meth1('foo', $bar) ?>
the output was <?php $this->eprint($output) ?>
These questions has probably been debated from time to time, and I'm sure
there's alot better answers. And I'd love to see some benchmarks and
comparisions. When everything comes around, it's just a matter of taste.
Örjan
|
mg [AT] memedia [DOT] de
2005-09-12 15:21:29 (964)
I actually see not much differences between Smarty and Savant. If you add
caching (what you really should do), it's basicaly almost smarty, except it
doesn't complie it's own language.
As far it goes wit Smarty, it IS a template language, e.g. you can capture
variables and it has a syntax easy enough for a webdesigners or maybe
customer to work with. I personaly think - if reduced to the thought, that
PHP itself is a scripting language - Smarty looks a bit overloadied with
functions not realy necassy.
Anyway, caching is necassy. And I also like using Pre- and Postfilters for
e.g. using "popup://" or "category://" and PNG-Fixes in a bigger
framework.
Comparing both would - so I expect - result in a similar speed. Anyway,
Savant looks a bit nicer ;)
|
anonymous
2005-08-22 14:22:18 (961)
More background:
$tpl->load('templatefile', 'sectionX');
$tpl->load('templatefile', 'sectionY');
$tpl->display(loadedtemplate);
What you'd do is load the sections you need, then when finished, render the
completed template that's in memory.
You wouldn't be opening/closing multiple template files from the
filesystem...
Patrick
|
contact [AT] jpprice [DOT] info
2005-08-22 14:18:32 (960)
Well, I was thinking of one template file containing sections that could be
loaded from that one file rather than having multiple template files sorted
by directory.
The idea is to have the one template file become a container for
interrelated sections as required. Another example:
main.tpl.php
<section1>
<strong>Invalid username/password</strong><br>
Please login!
</section1>
<section2>
Welcome back, <?php $this->username ?> !
</section2>
<section3>
You have <?= $this->new_message_count; ?> new messages in your inbox
</section3>
Then you might call these 'sections' with:
<?
if $auth->login_passed
$tpl->display('main.tpl.php', 'section2');
else
$tpl->display('main.tpl.php', 'section1');
With one template sectionalized, instead of loading a separate template
file for each bit of required html (or inlining the html in the logic) you
can pick and choose the appropriate html from one file, which again, acts
as a container.
This is really just an idea to keep from having a separate directory for a
bunch of template snippets that are related; the directory/multiple files
could be replaced instead with one file containing the separate sections
which are callable when rendering.
Anyway, I guess I don't understand the documentation here, where exactly
can I find documentation for the $tpl->template syntax? It's not in the
API unless I'm just brain dead.
Patrick
|
pmjones [AT] ciaweb [DOT] net
2005-08-19 16:16:39 (958)
Hi, Jpprice --
Savant already supports something like that; in Savant2, it's the
findTemplate() method, and in Savant3, it's the template() method. As you
say, create a file called 'header.tpl.php' or 'error.tpl.php'; then to
import it, do this in your template:
<?php include $this->template('error.tpl.php') ?>
Does that address your points?
|
contact [AT] jpprice [DOT] info
2005-08-19 15:54:25 (957)
Here's an idea which I saw implemented on an IBM AS/400 using a packaged
called cgidev2. It might be a useful addition to Savant...
The idea is to put all your random (or major) html snippets into one
(template) file, and name each section. The sections can then be called by
name in the template rendering function.
Here's an example of a template file:
<header> (use whatever tags you think appropriate)
html here
</header>
<error-message>
you're not logged in!<br>
</error-message>
<footer>
html here
</footer>
Now when you want to render a page, you could call it with
$tpl->displays('template','header')
$tpl->displays('template','error-message')
$tpl->displays('template','footer')
or for a normal template, leave the section blank:
$tpl->displays('template')
Of course, if the rendering function has high overhead this would be
overkill. If not, think of the possibilities of creating pages, having all
your html in one file, and keeping it out of your code....
Patrick Price
|
ruby [AT] jpprice [DOT] info
2005-08-04 18:28:49 (950)
Since you mentioned cacheing to speed things up, and since I presume you
have experience with Smarty, what are your findings on the relative speed
of PHP5 and Savant3 compared to Smarty et al and the "old" (inefficient?)
way of doing things?
Thanks!
-Patrick
|
pmjones [AT] ciaweb [DOT] net
2005-07-03 23:08:08 (933)
Hi, guys - quick note about caching. If you need a cache, try PEAR
Cache_Lite; if you need it within an application framework, try Solar_Cache
(http://solarphp.com).
By the time you get to the template, output caching is almost useless;
you've already spent the time building the data and assigning variables,
which is the most time-expensive portion of the script. Better to wrap a
an external cache around your view, than to have the view try to use an
internal cache.
Hope this makes sense.
-- pmj
|
mxvneli [at] gmx [doT] net
2005-07-03 19:44:01 (932)
Caching can be added as OPTIONAL feature. who wants could turn if on/off by
changing a config variable. i think it would be better so.
|
justin [DOT] randell [AT] gmail [DOT] com
2005-06-25 04:39:45 (925)
please don't add caching. i love the simplicity and power of this package.
to those who are asking for it: if your application needs caching, then
build something that uses the output of a savant template.
|
mxvneli [at] gmx [doT] net
2005-06-16 09:39:35 (917)
I agree with prevoius post. it would be cool to have both features. as of
caching - it could be added as option with on/off switching. the
possibility to use database fields as template content would be also great
and one more beat against smarty funs :D
|
anonymous
2005-06-15 18:01:07 (916)
Hiya,
is it possible to use database fields as template content instead of files,
and then use eval(), or would this be too much overhead? Also, is it
possible to implement some form of caching from PEAR ex. ?
|
pmjones [AT] ciaweb [DOT] net
2005-06-06 11:58:50 (908)
Hi, you.ve.got.mail,
I just added a boolean assign() test to the suite, and it appears to work
just fine; boolean true and boolean false look like they pass into the
template as expected. Please email me personally so we can discuss; or
even better, join the mailing list. :-)
|
you [DOT] ve [DOT] got [DOT] mail [AT] gmx [DOT] net
2005-06-06 11:03:02 (907)
Add to previous message:
when is do
---
if ($isRegion) {
$tpl->isRegion = true;
}
---
it works but not with:
$tpl->assign('isRegion', $isRegion);
|
you [DOT] ve [DOT] got [DOT] mail [AT] gmx [DOT] net
2005-06-06 10:57:05 (906)
Thanks for your great work :-)
I use Savant3 (3.0.0dev4) and can't assign a boolean value. It just won't
be able as true/false in the template. any hints?
so long -rg-
|
pmjones [AT] ciaweb [DOT] net
2005-06-01 16:54:41 (905)
Hi again, you.ve.got.mail,
You asked about assign() vs assignRef(). If you assign() and object by
name, that will go by reference (as you note). However, sometimes you may
want to assign an array or scalar variable by reference; for that, you can
use assignRef() to explicitly assign by reference.
Alternatively, you can do direct assignment ...
$Savant3->someVar =& $otherVar;
... which is the equivalent of:
$Savant3->assignRef('someVar', $otherVar);
Hope this helps.
|
pmjones [AT] ciaweb [DOT] net
2005-06-01 16:51:45 (904)
Hi, you.ve.got.mail --
API documentation is now available (I just added the link on the page
above). It's at:
http://phpsavant.com/api/Savant3/
We're working on "real" documentation even now. Thanks for your patience.
:-)
|
you [DOT] ve [DOT] got [DOT] mail [AT] gmx [DOT] net
2005-05-19 11:13:29 (893)
I like to start with php-templates and will try out savant3. is there a doc
for savant3 or are there any differences in the documentation to savant2 to
take care of?
what about assign vs. assingRef, as AFAIK php5 works "by ref" by default
now?
so long -rg-
|
pmjones [AT] ciaweb [DOT] net
2005-05-13 09:56:50 (891)
Hi, whump -- Q: "What was the motivation for changing the name of the
dateformat plugin to 'date'?" A: It's shorter. ;-)
Seriously, I figured as long as many of the "internal" methods were
changing around, I'd make other aesthetic changes as well. Sorry if it
caused too much sruprise; I would think a search-and-replace on
"$this->plugin('dateformat'," to "$this->date(" should be a quick fix. Let
me know, and thanks for using Savant. :-)
|
whump [AT] mac [DOT] com
2005-05-12 22:28:33 (890)
Everyone: there's test code in the tarball, that helped me figure out how
to transition from 2 to 3.
What was the motivation for changing the name of the dateformat plugin to
'date'?
I love the 'magic method' feature for calling plugins, much more elegant
than $this->plugin ('pluginname' ...) and must study your code.
|
norny [AT] yahoo [DOT] com
2005-04-22 23:27:38 (882)
Whew, good thing I looked at this before I got more than 10 lines of code
into writing my own class for it. Seems to work with what I've tried so
far.
|
pmjones [AT] ciaweb [DOT] net
2005-04-20 18:17:47 (879)
Hi, Norny -- you can turn off the automatic layout (i.e., the tables and
DIVs and stuff) by calling ...
$this->form('set', 'layout', false);
Hope this helps.
|
norny [AT] yahoo [DOT] com
2005-04-20 17:48:09 (878)
I used the form plugin for the first time today. I expected it, when I
wanted a select tag, to just print the select tag and its options. Instead,
it put it all inside a table. Then I tried PEAR's solutions and found they
did the same thing. I want to format the form outside the boundaries of a
table and still have something to loop through an array and make the tags
for me. Could there be an option, when starting the form perhaps, to turn
off the table and just print out the form-related tags where I put them?
Seems like that would be even simpler than formatting it all inside a
table. I haven't used Savant2, but it looks like it had the ability to do
that.
|
pookey [AT] pookey [DOT] co [DOT] uk
2005-04-15 13:32:09 (877)
it seems you no longer include sub-templates in teh same way (infact, if
you try, you get a seg fault). instead, do this:
<?php include $this->template('global/menu.tpl.php') ?>
Hope this helps.
|
pmjones [AT] ciaweb [DOT] net
2005-04-13 09:37:38 (876)
Hi, Nils -- thanks. :-)
|
php [AT] sowen [DOT] de
2005-04-13 09:28:55 (875)
Thanks for the bugfix.
I _REALLY_ meant "nice work", it was the only bug that I noticed, either
:-) Keep on going with this, like it so much better than Smarty.
Thanks, Nils
|
pmjones [AT] ciaweb [DOT] net
2005-04-02 21:51:28 (870)
Jadomingo, this is fixed in today's release of Savant3 (dev3). Thanks for
the report.
-- pmj
|
jadomingo [AT] gmail [DOT] com
2005-04-01 01:57:35 (869)
just browsed thru the code and on line 766, you need to change:
extract(get_object_vars($this, EXTR_REFS));
to:
extract(get_object_vars($this), EXTR_REFS);
other than that, still haven't noticed anything yet.
|
php [AT] sowen [DOT] de
2005-03-30 04:09:51 (868)
anonymous: Great help, thanks.
|
anonymous
2005-03-24 06:16:56 (860)
What is the favourite word of an idiot? Tell you - it is "I".
|
php [AT] sowen [DOT] de
2005-03-18 07:27:10 (857)
Nice work! I'm receiving a SEGFAULT with PHP5 when trying to call a method
on the Savant3-Object that actually doesn't exist. It seems that it tries
to load a plugin and crashs down. Might be a PHP5-problem, too.
My strace:
read(4, "\n<?php $this->segfault_demo(); ?"..., 8192) = 1017
read(4, "", 8192) = 0
read(4, "", 8192) = 0
close(4) = 0
lstat64("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/var/www", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
lstat64("/var/www/scheduler", {st_mode=S_IFDIR|0755, st_size=4096, ...}) =
0
lstat64("/var/www/scheduler/hk-libs", {st_mode=S_IFDIR|0755, st_size=4096,
...}) = 0
lstat64("/var/www/scheduler/hk-libs/savant", {st_mode=S_IFDIR|0755,
st_size=4096, ...}) = 0
lstat64("/var/www/scheduler/hk-libs/savant/Savant3", {st_mode=S_IFDIR|0755,
st_size=4096, ...}) = 0
lstat64("/var/www/scheduler/hk-libs/savant/Savant3/resources",
{st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/var/www", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
lstat64("/var/www/scheduler", {st_mode=S_IFDIR|0755, st_size=4096, ...}) =
0
lstat64("/var/www/scheduler/hk-libs", {st_mode=S_IFDIR|0755, st_size=4096,
...}) = 0
lstat64("/var/www/scheduler/hk-libs/savant", {st_mode=S_IFDIR|0755,
st_size=4096, ...}) = 0
lstat64("/var/www/scheduler/hk-libs/savant/Savant3", {st_mode=S_IFDIR|0755,
st_size=4096, ...}) = 0
lstat64("/var/www/scheduler/hk-libs/savant/Savant3/resources",
{st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat64("/var/www/scheduler/hk-libs/savant/Savant3/resources/Savant3_Plugin_segfault_demo.php",
0xbfff997c) = -1 ENOENT (No such file or directory)
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
Byebye, Nils
|
New comments are disabled.
|
|