⬆️ ⬇️

Quicky template review: Performance and Flexibility

Quicky is a hi-end template engine written in PHP, featuring flexible functionality and, at the same time, high performance. Based on the syntax and functionality of Smarty.




content:

- transition from Smarty to Quicky

- - than Quicky is better than Smarty?

- Quicky faster PHP-native?

- Quicky dark side force.

- Community Quicky. (now everything is here http://code.google.com/p/quicky/ )

- Rich Quicky features.

- Instead of conclusion. Personal opinion.



First of all, I want to say that I have been driving a whirlwind on a new project for a week now, so I can say this is the first impression, but at the same time a bug report was made, which was the reason for the release, so I didn’t waste my time.



I worked for Smarty, how can I try Quicky?



Kwiki is made in such a way that the transition to it is extremely simple to implement, because it supports the detailed syntax of the smart, down to the smallest detail, but generates much cleaner (including readable) and fast code, by the way, I note that it generates the code faster ( depending on the complexity of the template).

')

So, to try you need:

1. copy the latest distribution ( http://code.google.com/p/quicky/ ). There is always the latest stable version.

2. instruction quicky-tpl.net/ru/doc#p2

replace strings of the form

require ('Smarty.class.php');

$ tpl = new Smarty ();



on



require_once 'Quicky.class.php';

$ tpl = new Quicky;

$ tpl-> compiler_prefs ['interpritate_varname_params'] = true;

About this parameter you can read here: http://quicky-tpl.net/ru/forum,viewtopic,7/



In the vast majority of cases this is enough. A list of configuration parameters / existing functions can be found here: http://quicky-tpl.net/ru/doc#p3.2



If there are problems with loading plugins, then we are looking for an answer here:

http://quicky-tpl.net/ru/ideology



main fundamental difference:

All templates have a common scope.


it may also be the cause of the incompatibility of your project with kviki, but this is done out of principle, and not by accident.



is quicky better than smarty?



First , Kwiki has a much richer syntax. I will list the most commonly used in order of personal preference.

- In order to prevent the output of the Quicky-tag execution result on the screen, you need to add at the beginning of the '?', For example: {? $ X = 2 + 2}.

- Now you can forget about {math ...} , kviki allows you to write elementary and not just expressions directly in the output: {$ a + $ b}, {? $ C = sqrt ($ b)}

- The title in the closing tag can be omitted, that is, entries are allowed

{BLOCK} ... {/} ({if $ a} ... {/})


- There are well-proven blocks {switch}, {while}, {for} and others ...

- Output of the result of the work of admissible functions (admissible are those that do not change the state of external interfaces), for example: {str_repeat ("- =", 10)}

- Using constants and expressions in blocks: {foreach from = array ('One', 'Two', 'Three') key = "i" item = "text"}

- Magic constants to access the properties of the blocks. I mean, for example:
 {foreach name = my from = array ('One', 'Two', 'Three') key = "i" item = "text"}
     <u> {iteration} </ u>: {$ text} <br />
 {/ foreach} 


- Normal support for objects, that is, you can call something like: {$ obj-> method1 () -> property-> method ()}

second : Quickly faster.

- As I have already said, Kviki has a much more advanced compiler that does not generate a bunch of garbage, and also works faster by itself. read http://quicky-tpl.net/ru/ideology

- Block variables like first / last / index / index_prev / index_next are not stored in the template forming a mountain of code, but are calculated from the elementary ones (i.e. from i and size).

- {capture} by default does not use ob-functions, but merely indicates in the compiler an entry in a variable instead of echo.



third : Helpers (template functions).

Helper / function. Helpers can be created in templates, i.e. functions available inside the template.

They share a common scope with templates.

Example:

 {helper myhelper ($ a, $ b, $ c)}
 {? $ d = $ b * $ b-4 * $ a * $ c}
 {return array ((- $ b + sqrt ($ d)) / (2 * $ a), (- $ b-sqrt ($ d)) / (2 * $ a))}
 {/ helper} 




Quicky faster PHP-native?



Unbelievable, but true: kviki can be faster.

The secret lies in the compiler statements:

Compiler statements are executed only when the template is compiled, they affect the code of the compiled template, i.e. their result becomes static.



examples:

 {_foreach ..} {/}
 {_if ..} {/}
 {_include ..}
 in days {$ daySeconds = (_ 60 * 60 * 24)} seconds
 {? $ compileTime = (_ $ Quicky.now)}


In all examples, the results of the work of these operators will fall into the final template, that is, in fact, _ before the expression means eval () when compiling



Quicky dark side of power.



Kwiki is a very powerful and rich tool, if misused, it can “kill” your project (although it is always possible to pervert, as correctly noted). You choose for yourself the degree of responsibility to your colleagues - this is the price for incredible flexibility. If you are conservative, then kwiki will give you classic tools at a fundamentally new level of quality. If you are ambitious, then Kvivi will give you a Jedi sword, choose the color yourself =).



Community Quicky.



At the moment, kwiki is not very popular and its community is small, it officially exists here:

http://quicky-tpl.net/

The weak information illumination of kwiki is the only, in my opinion, essential flaw with which I tried to partially fight.

Author Kviki is one person, not a development team hiding under the pseudonym WP.

The speed of releases is directly proportional to your requests, in practice he himself was convinced that the author solves problems with bugs (if there are any) with quality: it is enough to post a bug report and get fixed in speed.

The project is about 2 years old, it is quite young, but it has long passed the alpha testing stage. Versions are numbered in such a way that the 3rd order indicates non-fundamental changes, but the second order is significant, the 4th order is usually bug fixes. Current version: 0.4.6.1



Quicky rich features.



In general, this is a topic for a separate article, and the experience of my work with them is not enough, so I will limit myself to brief descriptions (in the end, this is a review article)

- Blitz syntax support

- Quicky_form is a mechanism for interaction between the API and form elements, allowing you to impose dynamic forms ©

In general, you can learn more about them by looking at the examples, they are in the daddy / quicky / _test distribution.



Instead of a conclusion. Personal opinion.



As you may have noticed, my article is positive, and it’s true, I really liked Kwiki. I watched MACRO, used Smarti for a long time, wrote a project on ZFR, lived on PHP-native, but I like the smarti syntax and flexibility that kviki gives. I can not say that this is the best of the best, simply because I haven’t done a relatively “big” project for kviki, but I am sure that this may turn out to be true.



UPD:

1. for those who write something like: “yes, why do we need template engines in general!”, Please follow the link:

habrahabr.ru/blogs/php/27999 well or google, on request “why do we need template engines!”

2. Cons are a natural expression of your relationship.

Source: https://habr.com/ru/post/45337/



All Articles