changed git call from https to git readonly
[atutor.git] / mods / phpdoc2 / PhpDocumentor / phpDocumentor / Smarty-2.6.0 / FAQ
1 QUESTION INDEX\r
2 --------------\r
3 \r
4 GENERAL\r
5 \r
6 Q: What is Smarty?\r
7 Q: What's the difference between Smarty and other template engines?\r
8 Q: What do you mean "Compiled PHP Scripts" ?\r
9 Q: Why can't I just use PHPA (http://php-accelerator.co.uk) or Zend Cache?\r
10 Q: Why does smarty have a built in cache? Wouldn't it be better to handle this\r
11    in a separate class?\r
12 Q: Is Smarty faster than <insert other PHP template engine>?\r
13 Q: How can I be sure to get the best performance from Smarty?\r
14 Q: Do you have a mailing list?\r
15 Q: Can you change the mailing list so reply-to sends to the list and not the\r
16    user?\r
17 \r
18 TROUBLESHOOTING\r
19 \r
20 Q: Smarty doesn't work.\r
21 Q: I get the following error when running Smarty:\r
22    Warning:  Smarty error: problem creating directory "templates_c/239/239105369"\r
23    in /path/to/Smarty.class.php on line 542\r
24 Q: I get the following error when running Smarty:\r
25    Warning: Wrong parameter count for preg_replace() in\r
26    Smarty.class.php on line 371\r
27 Q: I get this error when passing variables to {include}:\r
28    Fatal error: Call to undefined function: get_defined_vars() in\r
29    /path/to/Smarty/templates_c/index.tpl.php on line 8\r
30 Q: I get PHP errors in my {if} tag logic.\r
31 Q: I'm changing my php code and/or templates, and my results are not getting\r
32    updated.\r
33 Q: I'm running Windows 2000 and I get blank content. My compiled PHP files are\r
34    also zero length.\r
35 Q: The template goes into an infinite loop when I include included templates\r
36    that pass local variables\r
37 Q: Javascript is causing Smarty errors in my templates.\r
38 Q: I get "SAFE MODE Restriction in effect. ..."-errors when running smarty.\r
39 \r
40 MISC\r
41 \r
42 Q: Can I use Macromedia's Dreamweaver to edit my templates?\r
43 Q: Dreamweaver is urlencoding the template delimiters when they are in a SRC or\r
44    HREF link. How do I get around this?\r
45 \r
46 HOWTO\r
47 \r
48 Q: How do I generate different cache files per template based on arguments\r
49    passed to the page?\r
50 Q: How do I pass a template variable as a parameter? {function param={$varname}}\r
51    does not work.\r
52 Q: How do I include cached template(s) within a non-cached template?\r
53 \r
54 \r
55 GENERAL\r
56 -------\r
57 \r
58 Q: What is Smarty?\r
59 A: Smarty is a template engine for PHP... but be aware this isn't just another\r
60    PHP template engine. It's much more than that.\r
61 \r
62 Q: What's the difference between Smarty and other template engines?\r
63 A: Most other template engines for PHP provide basic variable substitution and\r
64    dynamic block functionality. Smarty takes a step further to be a "smart"\r
65    template engine, adding features such as configuration files, template\r
66    functions, variable modifiers (see the docs!) and making all of this\r
67    functionality as easy as possible to use for both programmers and template\r
68    designers. Smarty also compiles the templates into PHP scripts, eliminating\r
69    the need to parse the templates on every invocation, making Smarty extremely\r
70    scalable and manageable for large application needs.\r
71 \r
72 Q: What do you mean "Compiled PHP Scripts" ?\r
73 A: Smarty reads the template files and creates PHP scripts from them. Once\r
74    these PHP scripts are created, Smarty executes these, never having to parse\r
75    the template files again. If you change a template file, Smarty will\r
76    recreate the PHP script for it. All this is done automatically by Smarty.\r
77    Template designers never need to mess with the generated PHP scripts or even\r
78    know of their existance. (NOTE: you can turn off this compile checking step\r
79    in Smarty for increased performance.)\r
80 \r
81 Q: Why can't I just use PHPA (http://php-accelerator.co.uk) or Zend Cache?\r
82 A: You certainly can, and we highly recommend it! What PHPA does is caches\r
83    compiled bytecode of your PHP scripts in shared memory or in a file. This\r
84    speeds up server response and saves the compilation step. Smarty creates PHP\r
85    scripts, which PHPA will cache nicely. Now, Smarty's built-in cache is\r
86    something completely different. It caches the _output_ of the template\r
87    contents. For example, if you have a template that requires several database\r
88    queries, Smarty can cache this output, saving the need to call the database\r
89    every time. Smarty and PHPA (or Zend Cache) complement each other nicely. If\r
90    performance is of the utmost importance, we would recommend using one of\r
91    these with any PHP application, using Smarty or not. As you can see in the\r
92    benchmarks, Smartys performance _really_ excels in combination with a PHP\r
93    accelerator.\r
94 \r
95 Q: Why does Smarty have a built in cache? Wouldn't it be better to handle this\r
96    in a separate class?\r
97 A: Smarty's caching functionality is tightly integrated with the template\r
98    engine, making it quite a bit more flexible than a simple caching wrapper.\r
99    For instance, you can cache select portions of a template page. Let's say\r
100    you have a polling box on your site. With Smarty, you can leave the poll\r
101    dynamic and cache the rest of the page. You can also pass templates\r
102    multiple cache ids, meaning that a template can have several caches\r
103    depending on URL, cookies, etc.\r
104 \r
105 Q: Is Smarty faster than <insert other PHP template engine>?\r
106 A: See the benchmark page for some performance comparisons. Smarty's approach\r
107    to templates is a bit different from some languages: it compiles templates\r
108    into PHP scripts instead of parsing them on each invocation. This usually\r
109    results in great performance gains, especially with complex templates.\r
110    Coupled with the built-in caching of Smarty templates, the performance is\r
111    outstanding.\r
112 \r
113 Q: How can I be sure to get the best performance from Smarty?\r
114 A: Be sure you set $compile_check=false once your templates are initially\r
115    compiled. This will skip the unneeded step of testing if the template has\r
116    changed since it was last compiled. If you have complex pages that don't\r
117    change too often, turn on the caching engine and adjust your application so\r
118    it doesn't do unnecessary work (like db calls) if a cached page is\r
119    available. See the documentation for examples.\r
120    \r
121 Q: Do you have a mailing list?\r
122 A:  We have a few mailing lists. "general" for you to share your ideas or ask\r
123         questions, "dev" for those interested in the development efforts of Smarty,\r
124         and "cvs" for those that would like to track the updates made in the cvs\r
125         repository.\r
126 \r
127     send a blank e-mail message to:\r
128       smarty-general-subscribe@lists.php.net (subscribe to the general list)\r
129       smarty-general-unsubscribe@lists.php.net (unsubscribe from the general list)\r
130       smarty-general-digest-subscribe@lists.php.net (subscribe to digest)\r
131       smarty-general-digest-unsubscribe@lists.php.net (unsubscribe from digest)\r
132       smarty-dev-subscribe@lists.php.net (subscribe to the dev list)\r
133       smarty-dev-unsubscribe@lists.php.net (unsubscribe from the dev list)\r
134       smarty-cvs-subscribe@lists.php.net (subscribe to the cvs list)\r
135       smarty-cvs-unsubscribe@lists.php.net (unsubscribe from the cvs list)\r
136     You can also browse the mailing list archives at\r
137     http://marc.theaimsgroup.com/?l=smarty&r=1&w=2\r
138 \r
139 \r
140 \r
141 Q: Can you change the mailing list so Reply-To sends to the list and not the\r
142    user?\r
143 A: Yes we could, but no we won't. Use "Reply-All" in your e-mail client to send\r
144    to the list. http://www.unicom.com/pw/reply-to-harmful.html\r
145 \r
146 TROUBLESHOOTING\r
147 ---------------\r
148 \r
149 Q: Smarty doesn't work.\r
150 A: You must be using PHP 4.0.6 or later if you use any version of Smarty\r
151    past 2.0.1. Read the BUGS file for more info.\r
152 \r
153 Q: I get the following error when running Smarty:\r
154    Warning:  Smarty error: problem creating directory "templates_c/239/239105369"\r
155    in /path/to/Smarty.class.php on line 542\r
156 A: Your web server user does not have permission to write to the templates_c\r
157    directory, or is unable to create the templates_c directory. Be sure the\r
158    templates_c directory exists in the location defined in Smarty.class.php,\r
159    and the web server user can write to it. If you do not know the web server\r
160    user, chmod 777 the templates_c directory, reload the page, then check the\r
161    file ownership of the files created in templates_c. Or, you can check the\r
162    httpd.conf (usually in /usr/local/apache/conf) file for this setting:\r
163    User nobody\r
164    Group nobody\r
165 \r
166 Q: I get the following error when running Smarty: Warning: Wrong parameter\r
167    count for preg_replace() in Smarty.class.php on line 371\r
168 A: preg_replace had a parameter added in PHP 4.0.2 that Smarty\r
169    requires. Upgrade to at least 4.0.6 to fix all known PHP issues with\r
170    Smarty.\r
171 \r
172 Q: I get this error when passing variables to {include}:\r
173    Fatal error: Call to undefined function: get_defined_vars() in\r
174    /path/to/Smarty/templates_c/index.tpl.php on line 8\r
175 A: get_defined_vars() was added to PHP 4.0.4. If you plan on passing\r
176    variables to included templates, you will need PHP 4.0.6 or later.\r
177 \r
178 Q: I get PHP errors in my {if} tag logic.\r
179 A: All conditional qualifiers must be separated by spaces. This syntax will not\r
180    work: {if $name=="Wilma"} You must instead do this: {if $name == "Wilma"}.\r
181    The reason for this is syntax ambiguity. Both "==" and "eq" are equivalent\r
182    in the template parser, so something like {if $nameeq"Wilma"} wouldn't be\r
183    parsable by the tokenizer.\r
184 \r
185 Q: I'm changing my php code and/or templates, and my results are not getting\r
186    updated.\r
187 A: This may be the result of your compile or cache settings. If you are\r
188    changing your php code, your templates will not necessarily get recompiled\r
189    to reflect the changes. Use $force_compile during develpment to avoid these\r
190    situations. Also turn off caching during development when you aren't\r
191    specifically testing it. You can also remove everything from your\r
192    compile_dir and cache_dir and reload the page to be sure everything gets\r
193    regenerated.\r
194 \r
195 Q: I'm running Windows 2000 and I get blank content. My compiled PHP files are\r
196    also zero length.\r
197 A: There seems to be a problem with some W2k machines and exclusive file\r
198    locking. Comment out the flock() call in _write_file to get around this,\r
199    although be aware this could possibly cause a problem with simultaneous\r
200    writes to a file, especially with caching turned on. NOTE: As of Smarty\r
201    1.4.0, a workaround was put in place that should solve this.\r
202 \r
203 Q: The template goes into an infinite loop when I include included templates\r
204    that pass local variables\r
205 A: This was fixed in 1.3.2 (new global attribute)\r
206 \r
207 Q: Javascript is causing Smarty errors in my templates.\r
208 A: Surround your javascript with {literal}{/literal} tags. See the docs.\r
209 \r
210 Q: I get "SAFE MODE Restriction in effect. ..."-errors when running smarty.\r
211 A: Use $smarty->use_sub_dirs = false when running php in safe mode.\r
212 \r
213 MISC\r
214 ----\r
215 \r
216 Q: Can I use Macromedia's Dreamweaver to edit my templates?\r
217 A: Certainly. You might want to change your tag delimiters from {} to something\r
218    that resembles valid HTML, like <!--{ }--> or <{ }> or something similar.\r
219    This way the editor won't view the template tags as errors.\r
220 \r
221 Q: Dreamweaver is urlencoding the template delimiters when they are in a SRC or\r
222    HREF link. How do I get around this?\r
223 A: In Edit - Properties - Rewrite HTML you can specify if Dreamweaver should\r
224    change special letters to %-equivalent or not. The default is on which\r
225    produces this error.\r
226 \r
227 HOWTO\r
228 -----\r
229    \r
230 Q: How do I generate different cache files per template based on arguments\r
231    passed to the page?\r
232 A: Use your $REQUEST_URI as the cache_id when fetching the page:\r
233 \r
234    global $REQUEST_URI; // if not already present\r
235    $smarty->display('index.tpl',$REQUEST_URI);\r
236 \r
237    This will create a separate cache file for each unique URL when you call\r
238    index.tpl. See the documentation for display() and fetch()\r
239 \r
240 Q: How do I pass a template variable as a parameter? {function param={$varname}}\r
241    does not work.\r
242 A: {function param=$varname} (You cannot nest template delimiters.)\r
243 \r
244 Q: How do I include cached template(s) within a non-cached template?\r
245 A: One way to do it:\r
246 \r
247    $smarty->caching = true;\r
248    $tpl1 = $smarty->fetch("internal1.tpl");\r
249    $tpl2 = $smarty->fetch("internal2.tpl");\r
250    $tpl3 = $smarty->fetch("internal3.tpl");\r
251 \r
252    $smarty->assign("tpl1_contents",$tpl1);\r
253    $smarty->assign("tpl2_contents",$tpl2);\r
254    $smarty->assign("tpl3_contents",$tpl3);\r
255 \r
256    $smarty->caching = false;\r
257    $smarty->display('index.tpl');\r
258 \r
259    index.tpl\r
260    ---------\r
261 \r
262    <table>\r
263            <tr>\r
264                    <td>{$tpl1_contents}</td>\r
265                    <td>{$tpl2_contents}</td>\r
266                    <td>{$tpl3_contents}</td>\r
267            </tr>\r
268    </table>\r
269 \r
270 \r
271 \r
272 \r
273    Another approach:\r
274 \r
275    You could write a custom insert function to fetch your internal\r
276    templates:\r
277 \r
278    <table>\r
279            <tr>\r
280                    <td>{insert name=fetch_tpl tpl="internal1.tpl"}</td>\r
281                    <td>{insert name=fetch_tpl tpl="internal2.tpl"}</td>\r
282                    <td>{insert name=fetch_tpl tpl="internal3.tpl"}</td>\r
283            </tr>\r
284    </table>\r