cvs: smarty-web / faq.php

From: Date: Wed, 01 May 2002 22:43:04 +0000
Subject: cvs: smarty-web / faq.php
Groups: php.smarty.cvs 
Request: Send a blank email to php-smarty-cvs+get-91@lists.php.net to get a copy of this message
mohrt Wed May 1 18:43:04 2002 EDT Modified files: /smarty-web faq.php Log: update FAQ

Index: smarty-web/faq.php diff -u smarty-web/faq.php:1.1.1.1 smarty-web/faq.php:1.2 --- smarty-web/faq.php:1.1.1.1 Mon Mar 25 12:21:00 2002 +++ smarty-web/faq.php Wed May 1 18:43:04 2002 @@ -8,135 +8,362 @@ <ul> -<li><a href="#1">What is PHP-GTK?</a> -<li><a href="#2">Why is it not working with the browser/web server?</a> -<li><a href="#3">How do I install PHP-GTK on Win32?</a> -<li><a href="#4">How do I use the buttons in GtkFileSelection?</a> -<li><a href="#5">How do I know which GTK Classes are supported?</a> -<li><a href="#6">Can I use Themes under Win32?</a> -<li><a href="#7">Where do I go from here?</a> +<li><a href="#1">What is Smarty?</a> +<li><a href="#2">What's the difference between Smarty and other template engines?</a> +<li><a href="#3">What do you mean "Compiled PHP Scripts"?</a> +<li><a href="#4">Why can't I just use PHPA (http://php-accelerator.co.uk) or Zend Cache?</a> +<li><a href="#5">Why does smarty have a built in cache? Wouldn't it be better to handle this in a separate class?</a> +<li><a href="#6">Is Smarty faster than &lt;insert other PHP template engine&gt;?</a> +<li><a href="#7"> How can I be sure to get the best performance from Smarty? +<li><a href="#8"> Do you have a mailing list? +<li><a href="#9"> Can you change the mailing list so reply-to sends to the list and not the user? </ul> +<p> +TROUBLESHOOTING +</p> + +<ul> +<li><a href="#10"> Smarty doesn't work. +<li><a href="#11"> I get the following error when running Smarty: + Warning: Smarty error: problem creating directory "templates_c/239/239105369" + in /path/to/Smarty.class.php on line 542 +<li><a href="#12"> I get the following error when running Smarty: + Warning: Wrong parameter count for preg_replace() in + Smarty.class.php on line 371 +<li><a href="#13"> I get this error when passing variables to {include}: + Fatal error: Call to undefined function: get_defined_vars() in + /path/to/Smarty/templates_c/index.tpl.php on line 8 +<li><a href="#14"> I get PHP errors in my {if} tag logic. +<li><a href="#15"> I'm changing my php code and/or templates, and my results are not getting + updated. +<li><a href="#16"> I'm running Windows 2000 and I get blank content. My compiled PHP files are + also zero length. +<li><a href="#17"> The template goes into an infinite loop when I include included templates + that pass local variables +<li><a href="#18"> Javascript is causing Smarty errors in my templates. +</ul> + +<p> +MISC +</p> + +<ul> +<li><a href="#19"> Can I use Macromedia's Dreamweaver to edit my templates? +<li><a href="#20"> Dreamweaver is urlencoding the template delimiters when they are in a SRC or HREF link. How do I get around this? +</ul> + +<p> +HOWTO +</p> + +<ul> +<li><a href="#21"> How do I generate different cache files per template based on arguments + passed to the page? +<li><a href="#22"> How do I pass a template variable as a parameter? {function param={$varname}} + does not work. +<li><a href="#23"> How do I include cached template(s) within a non-cached template? +</ul> + + + <DL> <DT> -<a name="1"><b>What is PHP-GTK?</b></a> +<a name="1"><b>What is Smarty?</b></a> +</DT> +<DD><P><PRE> +Smarty is a template engine for PHP... but be aware this isn't just another + PHP template engine. It's much more than that. +</PRE></P></DD> + + +<DT> +<a name="2"><b>What's the difference between Smarty and other template engines?</b></a> +</DT> +<DD><P><PRE> + Most other template engines for PHP provide basic variable substitution and + dynamic block functionality. Smarty takes a step further to be a "smart" + template engine, adding features such as configuration files, template + functions, variable modifiers (see the docs!) and making all of this + functionality as easy as possible to use for both programmers and template + designers. Smarty also compiles the templates into PHP scripts, eliminating + the need to parse the templates on every invocation, making Smarty extremely + scalable and managable for large application needs. +</PRE></P></DD> + +<DT> +<a name="3"><b>What do you mean "Compiled PHP Scripts"?</b></a> +</DT> +<DD><P><PRE> + Smarty reads the template files and creates PHP scripts from them. Once + these PHP scripts are created, Smarty executes these, never having to parse + the template files again. If you change a template file, Smarty will + recreate the PHP script for it. All this is done automatically by Smarty. + Template designers never need to mess with the generated PHP scripts or even + know of their existance. (NOTE: you can turn off this compile checking step + in Smarty for increased performance.) +</PRE></P></DD> + +<DT> +<a name="4"><b>Why can't I just use PHPA (http://php-accelerator.co.uk) or Zend Cache?</b></a> +</DT> +<DD><P><PRE> + You certainly can, and we highly recommend it! What PHPA does is caches + compiled bytecode of your PHP scripts in shared memory or in a file. This + speeds up server response and saves the compilation step. Smarty creates PHP + scripts, which PHPA will cache nicely. Now, Smarty's built-in cache is + something completely different. It caches the _output_ of the template + contents. For example, if you have a template that requires several database + queries, Smarty can cache this output, saving the need to call the database + every time. Smarty and PHPA (or Zend Cache) complement each other nicely. If + performance is of the utmost importance, we would recommend using one of + these with any PHP application, using Smarty or not. As you can see in the + benchmarks, Smartys performance _really_ excels in combination with a PHP + accelerator. +</PRE></P></DD> + +<DT> +<a name="5"><b>Why does Smarty have a built in cache? Wouldn't it be better to handle this in a separate class?</b></a> +</DT> +<DD><P><PRE> + Smarty's caching functionality is tightly integrated with the template + engine, making it quite a bit more flexible than a simple caching wrapper. + For instance, you can cache select portions of a template page. Let's say + you have a polling box on your site. With Smarty, you can leave the poll + dynamic and cache the rest of the page. You can also pass templates + multiple cache ids, meaning that a template can have several caches + depending on URL, cookies, etc. +</PRE></P></DD> + +<DT> +<a name="6"><b>Is Smarty faster than &lt;insert other PHP template engine&gt;?</b></a> +</DT> +<DD><P><PRE> + See the benchmark page for some performance comparisons. Smarty's approach + to templates is a bit different from some languages: it compiles templates + into PHP scripts instead of parsing them on each invocation. This usually + results in great performance gains, especially with complex templates. + Coupled with the built-in caching of Smarty templates, the performance is + outstanding. +</PRE></P></DD> + +<DT> +<a name="7"><b>How can I be sure to get the best performance from Smarty?</b></a> +</DT> +<DD><P><PRE> + Be sure you set $compile_check=false once your templates are initially + compiled. This will skip the unneeded step of testing if the template has + changed since it was last compiled. If you have complex pages that don't + change too often, turn on the caching engine and adjust your application so + it doesn't do unnecessary work (like db calls) if a cached page is + available. See the documentation for examples. +</PRE></P></DD> + +<DT> +<a name="8"><b>Do you have a mailing list?</b></a> +</DT> +<DD><P><PRE> + We have a few mailing lists. "general" for you to share your ideas or ask + questions, "dev" for those interested in the development efforts of Smarty, + and "cvs" for those that would like to track the updates made in the cvs + repository. + + send a blank e-mail message to: + smarty-general-subscribe@lists.php.net (subscribe to the general list) + smarty-general-unsubscribe@lists.php.net (unsubscribe from the general list) + smarty-general-digest-subscribe@lists.php.net (subscribe to digest) + smarty-general-digest-unsubscribe@lists.php.net (unsubscribe from digest) + smarty-dev-subscribe@lists.php.net (subscribe to the dev list) + smarty-dev-unsubscribe@lists.php.net (unsubscribe from the dev list) + smarty-cvs-subscribe@lists.php.net (subscribe to the cvs list) + smarty-cvs-unsubscribe@lists.php.net (unsubscribe from the cvs list) + You can also browse the mailing list archives at + <a href="http://marc.theaimsgroup.com/?l=smarty&r=1&w=2">http://marc.theaimsgroup.com/?l=smarty&r=1&w=2</a> +</PRE></P></DD> + +<DT> +<a name="9"><b>Can you change the mailing list so Reply-To sends to the list and not the user?</b></a> +</DT> +<DD><P><PRE> + Yes we could, but no we won't. Use "Reply-All" in your e-mail client to send + to the list. <a href="http://www.unicom.com/pw/reply-to-harmful.html">http://www.unicom.com/pw/reply-to-harmful.html</a> +</PRE></P></DD> + +<DT> +<a name="10"><b>Smarty doesn't work.</b></a> +</DT> +<DD><P><PRE> + You must be using PHP 4.0.6 or later if you use any version of Smarty + past 2.0.1. Read the BUGS file for more info. +</PRE></P></DD> + +<DT> +<a name="11"><b> + Q: I get the following error when running Smarty: + Warning: Smarty error: problem creating directory "templates_c/239/239105369" + in /path/to/Smarty.class.php on line 542</b></a> +</DT> +<DD><P><PRE> + Your web server user does not have permission to write to the templates_c + directory, or is unable to create the templates_c directory. Be sure the + templates_c directory exists in the location defined in Smarty.class.php, + and the web server user can write to it. If you do not know the web server + user, chmod 777 the templates_c directory, reload the page, then check the + file ownership of the files created in templates_c. Or, you can check the + httpd.conf (usually in /usr/local/apache/conf) file for this setting: + User nobody + Group nobody +</PRE></P></DD> + +<DT> +<a name="12"><b>I get the following error when running Smarty: Warning: Wrong parameter + count for preg_replace() in Smarty.class.php on line 371</b></a> +</DT> +<DD><P><PRE> + preg_replace had a parameter added in PHP 4.0.2 that Smarty + requires. Upgrade to at least 4.0.6 to fix all known PHP issues with + Smarty. +</PRE></P></DD> + +<DT> + <a name="13"><b>I get this error when passing variables to {include}: + Fatal error: Call to undefined function: get_defined_vars() in + /path/to/Smarty/templates_c/index.tpl.php on line 8</b></a> +</DT> +<DD><P><PRE> + get_defined_vars() was added to PHP 4.0.4. If you plan on passing + variables to included templates, you will need PHP 4.0.6 or later. +</PRE></P></DD> + +<DT> +<a name="14"><b>I get PHP errors in my {if} tag logic.</b></a> +</DT> +<DD><P><PRE> + All conditional qualifiers must be separated by spaces. This syntax will not + work: {if $name=="Wilma"} You must instead do this: {if $name == "Wilma"}. + The reason for this is syntax ambiguity. Both "==" and "eq" are equivalent + in the template parser, so something like {if $nameeq"Wilma"} wouldn't be + parsable by the tokenizer. +</PRE></P></DD> + +<DT> +<a name="15"><b>I'm changing my php code and/or templates, and my results are not getting + updated.</b></a> +</DT> +<DD><P><PRE> + This may be the result of your compile or cache settings. If you are + changing your php code, your templates will not necessarily get recompiled + to reflect the changes. Use $force_compile during develpment to avoid these + situations. Also turn off caching during development when you aren't + specifically testing it. You can also remove everything from your + compile_dir and cache_dir and reload the page to be sure everything gets + regenerated. +</PRE></P></DD> + +<DT> +<a name="16"><b>I'm running Windows 2000 and I get blank content. My compiled PHP files are + also zero length.</b></a> +</DT> +<DD><P><PRE> + There seems to be a problem with some W2k machines and exclusive file + locking. Comment out the flock() call in _write_file to get around this, + although be aware this could possibly cause a problem with simultaneous + writes to a file, especially with caching turned on. NOTE: As of Smarty + 1.4.0, a workaround was put in place that should solve this. +</PRE></P></DD> + +<DT> +<a name="17"><b>The template goes into an infinite loop when I include included templates + that pass local variables</b></a> +</DT> +<DD><P><PRE> + This was fixed in 1.3.2 (new global attribute) +</PRE></P></DD> + +<DT> +<a name="18"><b>Javascript is causing Smarty errors in my templates.</b></a> </DT> -<DD><P> -PHP-GTK is a PHP extension that implements language bindings for GTK+. It -provides an object-oriented interface to GTK+ classes and functions and greatly -simplifies writing client side cross-platform GUI applications. -</P></DD> - - -<DT> -<a name="2"><b>Why is it not working with the browser/web server?</b></a> -</DT> -<DD><P> -PHP-GTK is not meant to be used in the Web environment. It is intended for -creation of standalone applications (run via command-line, user's desktop, etc.). -</P></DD> - -<DT> -<a name="3"><b>How do I install PHP-GTK on Win32?</b></a> -</DT> -<DD><P> -Download the latest binaries from <? print_link('/download.php', 'gtk.php.net'); ?>. -The zip file contains all binaries needed to run PHP-GTK. Copy the files to the following locations: -</P></DD> -<DD><P> -<B>For Windows 98/NT/2000:</B> -</P></DD> -<DD><P> -In your PHP directory (e.g., c:\php4): -<UL> - <LI>php.exe - <LI>php4ts.dll - <LI>php_gtk.dll -</UL> -In your Windows directory (e.g., c:\winnt or c:\windows): -<UL> - <LI>php.ini -</UL> -In your System32 directory (e.g., c:\winnt\system32 or c:\windows\system32): -<UL> - <LI>gtk-1.3.dll - <LI>gdk-1.3.dll - <LI>gmodule-1.3.dll - <LI>glib-1.3.dll - <LI>iconv-1.3.dll - <LI>gnu-intl.dll -</UL> -</P></DD> -<DD><P> -<B>For Windows 95:</B> -</P></DD> -<DD><P> -PHP-GTK has <b>not</b> been tested on Windows 95 ... sorry. -</P></DD> - - -<DT> -<a name="4"><b>How do I use the buttons in GtkFileSelection?</b></a> -</DT> -<DD><P> -<PRE CLASS="code"> -// Create the dialog window: - $fs = &new GtkFileSelection("Save file"); - -// Get a handle to the Ok button: - $ok_button = $fs->ok_button; - -// Connect a function: - $ok_button->connect("clicked", "enddialog"); - -// Connect the destroy action on the dialog window: - $ok_button->connect_object("clicked", "destroy", $fs); -</PRE> -</P></DD> -<DD><P> -It is <B>not</B> currently possible to do it this way: -<PRE CLASS="code"> -// Create the dialog window - $fs = &new GtkFileSelection("Save file"); - -// Connect a function - $fs->ok_button->connect("clicked", "enddialog"); - -// Connect the destroy action on the dialog window - $fs->ok_button->connect_object("clicked", "destroy", $fs); -</PRE> -</P></DD> - -<DT> -<a name="5"><b>How do I know which GTK Classes are supported?</b></a> -</DT> -<DD><P> -The following code will show the defined classes. All the PHP-GTK -classes will be listed along with one or two others. -<PRE CLASS="code"> -$array = get_declared_classes(); -while(list(,$classname) = each($array)) { - echo $classname."\n"; -} -</PRE> -See the <?php print_link('http://www.php.net/manual/en/ref.classobj.php', 'Class/Object functions'); ?> -in the PHP Manual for other useful functions. -</P></DD> - -<DT> -<a name="6"><b>Can I use Themes under Win32?</b></a> -</DT> -<DD><P> -No, The Win32 GTK port does not currently support this. -</P></DD> - -<DT> -<a name="7"><b>Where do I go from here?</b></a> -</DT> -<DD><P> -Check out the <?php print_link('/resources.php', 'Resources page'); ?>. -</P></DD> +<DD><P><PRE> + Surround your javascript with {literal}{/literal} tags. See the docs. +</PRE></P></DD> + +<DT> +<a name="19"><b>Can I use Macromedia's Dreamweaver to edit my templates?</b></a> +</DT> +<DD><P><PRE> + Certainly. You might want to change your tag delimiters from {} to something + that resembles valid HTML, like <!--{ }--> or <{ }> or something similar. + This way the editor won't view the template tags as errors. +</PRE></P></DD> + +<DT> +<a name="20"><b>Dreamweaver is urlencoding the template delimiters when they are in a SRC or + HREF link. How do I get around this?</b></a> +</DT> +<DD><P><PRE> + In Edit - Properties - Rewrite HTML you can specify if Dreamweaver should + change special letters to %-equivalent or not. The default is on which + produces this error. +</PRE></P></DD> + +<a name="21"><b>How do I generate different cache files per template based on arguments + passed to the page?</b></a> +</DT> +<DD><P><PRE> + Use your $REQUEST_URI as the cache_id when fetching the page: + + global $REQUEST_URI; // if not already present + $smarty->display('index.tpl',$REQUEST_URI); + + This will create a separate cache file for each unique URL when you call + index.tpl. See the documentation for display() and fetch() + +</PRE></P></DD> + +<a name="22"><b>How do I pass a template variable as a parameter? {function param={$varname}} + does not work.</b></a> +</DT> +<DD><P><PRE> + {function param=$varname} (You cannot nest template delimiters.) + +</PRE></P></DD> + +<a name="23"><b>How do I include cached template(s) within a non-cached template?</b></a> +</DT> +<DD><P><PRE> + One way to do it: + + $smarty->caching = true; + $tpl1 = $smarty->fetch("internal1.tpl"); + $tpl2 = $smarty->fetch("internal2.tpl"); + $tpl3 = $smarty->fetch("internal3.tpl"); + + $smarty->assign("tpl1_contents",$tpl1); + $smarty->assign("tpl2_contents",$tpl2); + $smarty->assign("tpl3_contents",$tpl3); + + $smarty->caching = false; + $smarty->display('index.tpl'); + + index.tpl + --------- + + &lt;table&gt; + &lt;tr&gt; + &lt;td&gt;{$tpl1_contents}&lt;/td&gt; + &lt;td&gt;{$tpl2_contents}&lt;/td&gt; + &lt;td&gt;{$tpl3_contents}&lt;/td&gt; + &lt;/tr&gt; + &lt;/table&gt; + + Another approach: + + You could write a custom insert function to fetch your internal + templates: + + <table> +</PRE></P></DD> </DL>
« previous php.smarty.cvs (#91) next »