PHP Smarty

PHP Smarty Interview Questions:

1. What is Smarty?

Smarty is a template engine for PHP… but be aware this isn’t just another
PHP template engine. It’s much more than that.

2. What’s the difference between Smarty and other template engines?

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 manageable for large application needs.

3. What do you mean “Compiled PHP Scripts”?

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.)

4. Why can’t I just use PHPA (http://php-accelerator.co.uk) or Zend Cache?

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.

5. Why does Smarty have a built in cache? Wouldn’t it be better to handle this in a separate class?

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.

6. Is Smarty faster than ?

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.

7.How can I be sure to get the best performance from Smarty?

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.

8.Do you have a mailing list?

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
http://marc.theaimsgroup.com/?l=smarty&r=1&w=2

9. Can you change the mailing list so Reply-To sends to the list and not the user?

Yes we could, but no we won’t. Use “Reply-All” in your e-mail client to send
to the list. http://www.unicom.com/pw/reply-to-harmful.html

10. Smarty doesn’t work.

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.

Posted By:

AentteQ Software Technologies




PL

Advertisements
%d bloggers like this: