+++ /dev/null
-QUESTION INDEX\r
---------------\r
-\r
-GENERAL\r
-\r
-Q: What is Smarty?\r
-Q: What's the difference between Smarty and other template engines?\r
-Q: What do you mean "Compiled PHP Scripts" ?\r
-Q: Why can't I just use PHPA (http://php-accelerator.co.uk) or Zend Cache?\r
-Q: Why does smarty have a built in cache? Wouldn't it be better to handle this\r
- in a separate class?\r
-Q: Is Smarty faster than <insert other PHP template engine>?\r
-Q: How can I be sure to get the best performance from Smarty?\r
-Q: Do you have a mailing list?\r
-Q: Can you change the mailing list so reply-to sends to the list and not the\r
- user?\r
-\r
-TROUBLESHOOTING\r
-\r
-Q: Smarty doesn't work.\r
-Q: I get the following error when running Smarty:\r
- Warning: Smarty error: problem creating directory "templates_c/239/239105369"\r
- in /path/to/Smarty.class.php on line 542\r
-Q: I get the following error when running Smarty:\r
- Warning: Wrong parameter count for preg_replace() in\r
- Smarty.class.php on line 371\r
-Q: I get this error when passing variables to {include}:\r
- Fatal error: Call to undefined function: get_defined_vars() in\r
- /path/to/Smarty/templates_c/index.tpl.php on line 8\r
-Q: I get PHP errors in my {if} tag logic.\r
-Q: I'm changing my php code and/or templates, and my results are not getting\r
- updated.\r
-Q: I'm running Windows 2000 and I get blank content. My compiled PHP files are\r
- also zero length.\r
-Q: The template goes into an infinite loop when I include included templates\r
- that pass local variables\r
-Q: Javascript is causing Smarty errors in my templates.\r
-Q: I get "SAFE MODE Restriction in effect. ..."-errors when running smarty.\r
-\r
-MISC\r
-\r
-Q: Can I use Macromedia's Dreamweaver to edit my templates?\r
-Q: Dreamweaver is urlencoding the template delimiters when they are in a SRC or\r
- HREF link. How do I get around this?\r
-\r
-HOWTO\r
-\r
-Q: How do I generate different cache files per template based on arguments\r
- passed to the page?\r
-Q: How do I pass a template variable as a parameter? {function param={$varname}}\r
- does not work.\r
-Q: How do I include cached template(s) within a non-cached template?\r
-\r
-\r
-GENERAL\r
--------\r
-\r
-Q: What is Smarty?\r
-A: Smarty is a template engine for PHP... but be aware this isn't just another\r
- PHP template engine. It's much more than that.\r
-\r
-Q: What's the difference between Smarty and other template engines?\r
-A: Most other template engines for PHP provide basic variable substitution and\r
- dynamic block functionality. Smarty takes a step further to be a "smart"\r
- template engine, adding features such as configuration files, template\r
- functions, variable modifiers (see the docs!) and making all of this\r
- functionality as easy as possible to use for both programmers and template\r
- designers. Smarty also compiles the templates into PHP scripts, eliminating\r
- the need to parse the templates on every invocation, making Smarty extremely\r
- scalable and manageable for large application needs.\r
-\r
-Q: What do you mean "Compiled PHP Scripts" ?\r
-A: Smarty reads the template files and creates PHP scripts from them. Once\r
- these PHP scripts are created, Smarty executes these, never having to parse\r
- the template files again. If you change a template file, Smarty will\r
- recreate the PHP script for it. All this is done automatically by Smarty.\r
- Template designers never need to mess with the generated PHP scripts or even\r
- know of their existance. (NOTE: you can turn off this compile checking step\r
- in Smarty for increased performance.)\r
-\r
-Q: Why can't I just use PHPA (http://php-accelerator.co.uk) or Zend Cache?\r
-A: You certainly can, and we highly recommend it! What PHPA does is caches\r
- compiled bytecode of your PHP scripts in shared memory or in a file. This\r
- speeds up server response and saves the compilation step. Smarty creates PHP\r
- scripts, which PHPA will cache nicely. Now, Smarty's built-in cache is\r
- something completely different. It caches the _output_ of the template\r
- contents. For example, if you have a template that requires several database\r
- queries, Smarty can cache this output, saving the need to call the database\r
- every time. Smarty and PHPA (or Zend Cache) complement each other nicely. If\r
- performance is of the utmost importance, we would recommend using one of\r
- these with any PHP application, using Smarty or not. As you can see in the\r
- benchmarks, Smartys performance _really_ excels in combination with a PHP\r
- accelerator.\r
-\r
-Q: Why does Smarty have a built in cache? Wouldn't it be better to handle this\r
- in a separate class?\r
-A: Smarty's caching functionality is tightly integrated with the template\r
- engine, making it quite a bit more flexible than a simple caching wrapper.\r
- For instance, you can cache select portions of a template page. Let's say\r
- you have a polling box on your site. With Smarty, you can leave the poll\r
- dynamic and cache the rest of the page. You can also pass templates\r
- multiple cache ids, meaning that a template can have several caches\r
- depending on URL, cookies, etc.\r
-\r
-Q: Is Smarty faster than <insert other PHP template engine>?\r
-A: See the benchmark page for some performance comparisons. Smarty's approach\r
- to templates is a bit different from some languages: it compiles templates\r
- into PHP scripts instead of parsing them on each invocation. This usually\r
- results in great performance gains, especially with complex templates.\r
- Coupled with the built-in caching of Smarty templates, the performance is\r
- outstanding.\r
-\r
-Q: How can I be sure to get the best performance from Smarty?\r
-A: Be sure you set $compile_check=false once your templates are initially\r
- compiled. This will skip the unneeded step of testing if the template has\r
- changed since it was last compiled. If you have complex pages that don't\r
- change too often, turn on the caching engine and adjust your application so\r
- it doesn't do unnecessary work (like db calls) if a cached page is\r
- available. See the documentation for examples.\r
- \r
-Q: Do you have a mailing list?\r
-A: We have a few mailing lists. "general" for you to share your ideas or ask\r
- questions, "dev" for those interested in the development efforts of Smarty,\r
- and "cvs" for those that would like to track the updates made in the cvs\r
- repository.\r
-\r
- send a blank e-mail message to:\r
- smarty-general-subscribe@lists.php.net (subscribe to the general list)\r
- smarty-general-unsubscribe@lists.php.net (unsubscribe from the general list)\r
- smarty-general-digest-subscribe@lists.php.net (subscribe to digest)\r
- smarty-general-digest-unsubscribe@lists.php.net (unsubscribe from digest)\r
- smarty-dev-subscribe@lists.php.net (subscribe to the dev list)\r
- smarty-dev-unsubscribe@lists.php.net (unsubscribe from the dev list)\r
- smarty-cvs-subscribe@lists.php.net (subscribe to the cvs list)\r
- smarty-cvs-unsubscribe@lists.php.net (unsubscribe from the cvs list)\r
- You can also browse the mailing list archives at\r
- http://marc.theaimsgroup.com/?l=smarty&r=1&w=2\r
-\r
-\r
-\r
-Q: Can you change the mailing list so Reply-To sends to the list and not the\r
- user?\r
-A: Yes we could, but no we won't. Use "Reply-All" in your e-mail client to send\r
- to the list. http://www.unicom.com/pw/reply-to-harmful.html\r
-\r
-TROUBLESHOOTING\r
----------------\r
-\r
-Q: Smarty doesn't work.\r
-A: You must be using PHP 4.0.6 or later if you use any version of Smarty\r
- past 2.0.1. Read the BUGS file for more info.\r
-\r
-Q: I get the following error when running Smarty:\r
- Warning: Smarty error: problem creating directory "templates_c/239/239105369"\r
- in /path/to/Smarty.class.php on line 542\r
-A: Your web server user does not have permission to write to the templates_c\r
- directory, or is unable to create the templates_c directory. Be sure the\r
- templates_c directory exists in the location defined in Smarty.class.php,\r
- and the web server user can write to it. If you do not know the web server\r
- user, chmod 777 the templates_c directory, reload the page, then check the\r
- file ownership of the files created in templates_c. Or, you can check the\r
- httpd.conf (usually in /usr/local/apache/conf) file for this setting:\r
- User nobody\r
- Group nobody\r
-\r
-Q: I get the following error when running Smarty: Warning: Wrong parameter\r
- count for preg_replace() in Smarty.class.php on line 371\r
-A: preg_replace had a parameter added in PHP 4.0.2 that Smarty\r
- requires. Upgrade to at least 4.0.6 to fix all known PHP issues with\r
- Smarty.\r
-\r
-Q: I get this error when passing variables to {include}:\r
- Fatal error: Call to undefined function: get_defined_vars() in\r
- /path/to/Smarty/templates_c/index.tpl.php on line 8\r
-A: get_defined_vars() was added to PHP 4.0.4. If you plan on passing\r
- variables to included templates, you will need PHP 4.0.6 or later.\r
-\r
-Q: I get PHP errors in my {if} tag logic.\r
-A: All conditional qualifiers must be separated by spaces. This syntax will not\r
- work: {if $name=="Wilma"} You must instead do this: {if $name == "Wilma"}.\r
- The reason for this is syntax ambiguity. Both "==" and "eq" are equivalent\r
- in the template parser, so something like {if $nameeq"Wilma"} wouldn't be\r
- parsable by the tokenizer.\r
-\r
-Q: I'm changing my php code and/or templates, and my results are not getting\r
- updated.\r
-A: This may be the result of your compile or cache settings. If you are\r
- changing your php code, your templates will not necessarily get recompiled\r
- to reflect the changes. Use $force_compile during develpment to avoid these\r
- situations. Also turn off caching during development when you aren't\r
- specifically testing it. You can also remove everything from your\r
- compile_dir and cache_dir and reload the page to be sure everything gets\r
- regenerated.\r
-\r
-Q: I'm running Windows 2000 and I get blank content. My compiled PHP files are\r
- also zero length.\r
-A: There seems to be a problem with some W2k machines and exclusive file\r
- locking. Comment out the flock() call in _write_file to get around this,\r
- although be aware this could possibly cause a problem with simultaneous\r
- writes to a file, especially with caching turned on. NOTE: As of Smarty\r
- 1.4.0, a workaround was put in place that should solve this.\r
-\r
-Q: The template goes into an infinite loop when I include included templates\r
- that pass local variables\r
-A: This was fixed in 1.3.2 (new global attribute)\r
-\r
-Q: Javascript is causing Smarty errors in my templates.\r
-A: Surround your javascript with {literal}{/literal} tags. See the docs.\r
-\r
-Q: I get "SAFE MODE Restriction in effect. ..."-errors when running smarty.\r
-A: Use $smarty->use_sub_dirs = false when running php in safe mode.\r
-\r
-MISC\r
-----\r
-\r
-Q: Can I use Macromedia's Dreamweaver to edit my templates?\r
-A: Certainly. You might want to change your tag delimiters from {} to something\r
- that resembles valid HTML, like <!--{ }--> or <{ }> or something similar.\r
- This way the editor won't view the template tags as errors.\r
-\r
-Q: Dreamweaver is urlencoding the template delimiters when they are in a SRC or\r
- HREF link. How do I get around this?\r
-A: In Edit - Properties - Rewrite HTML you can specify if Dreamweaver should\r
- change special letters to %-equivalent or not. The default is on which\r
- produces this error.\r
-\r
-HOWTO\r
------\r
- \r
-Q: How do I generate different cache files per template based on arguments\r
- passed to the page?\r
-A: Use your $REQUEST_URI as the cache_id when fetching the page:\r
-\r
- global $REQUEST_URI; // if not already present\r
- $smarty->display('index.tpl',$REQUEST_URI);\r
-\r
- This will create a separate cache file for each unique URL when you call\r
- index.tpl. See the documentation for display() and fetch()\r
-\r
-Q: How do I pass a template variable as a parameter? {function param={$varname}}\r
- does not work.\r
-A: {function param=$varname} (You cannot nest template delimiters.)\r
-\r
-Q: How do I include cached template(s) within a non-cached template?\r
-A: One way to do it:\r
-\r
- $smarty->caching = true;\r
- $tpl1 = $smarty->fetch("internal1.tpl");\r
- $tpl2 = $smarty->fetch("internal2.tpl");\r
- $tpl3 = $smarty->fetch("internal3.tpl");\r
-\r
- $smarty->assign("tpl1_contents",$tpl1);\r
- $smarty->assign("tpl2_contents",$tpl2);\r
- $smarty->assign("tpl3_contents",$tpl3);\r
-\r
- $smarty->caching = false;\r
- $smarty->display('index.tpl');\r
-\r
- index.tpl\r
- ---------\r
-\r
- <table>\r
- <tr>\r
- <td>{$tpl1_contents}</td>\r
- <td>{$tpl2_contents}</td>\r
- <td>{$tpl3_contents}</td>\r
- </tr>\r
- </table>\r
-\r
-\r
-\r
-\r
- Another approach:\r
-\r
- You could write a custom insert function to fetch your internal\r
- templates:\r
-\r
- <table>\r
- <tr>\r
- <td>{insert name=fetch_tpl tpl="internal1.tpl"}</td>\r
- <td>{insert name=fetch_tpl tpl="internal2.tpl"}</td>\r
- <td>{insert name=fetch_tpl tpl="internal3.tpl"}</td>\r
- </tr>\r
- </table>\r