📜 ⬆️ ⬇️

PHP Template Quicky Version 0.5.x

Major changes from 0.4.x: ( http://code.google.com/p/quicky/ )
[~] {math} is now compiled into native PHP code.
[~] Line numbers are displayed in case of compilation errors, compilation errors are displayed all at once, and not one by one, the tag in which the error is shown.
[+] Added function {debug} displaying debug-console ( about why Quicky has the most advanced debugger read under the cut ).

[+] local variables
What is Kwiki read here:
habrahabr.ru/blogs/php/45337

Briefly about what is Quicky:

if you have Smarty and you are generally satisfied with his idea, but his speed and ugly constructions, such as math (although someone is rushing) are not satisfied, then Quicky is what you need. almost full syntax support (templates do not have to be rewritten, well, or at least)

for details now about the changes.

Debug


Kwiki debug was earlier at a lower level than smarti, but the problem arose and was resolved.
{debug} was originally partitioned with smarti, but it soon became clear that it did not solve all the problems.
- First and foremost. Error output format: now it is clearly indicated on which template string, and not just the tag start string
Quickly syntax error Unexpected constant "a" in template extreme / bugreport.tpl on line 3 (starts at line 1)
Tag: {a}
- Second: part debug has been finalized. Large blocks of text are folded to [...] and indicate the length of the text, by clicking on the dots, the entire text block is expanded.
- Third: in debug_mode mode, you see on which line and in which file the variable was registered in Shabolon (a very useful feature, especially when parsing the old code)
- Fourth: the output of the available methods of registered objects (not sure that this has already been done, but if not done, it will be soon)
UPD: I want to tell you more about the debug of registered objects. The task in the general case is this: register the auxiliary object in the template engine and so that the coder can now deal with it himself. Now it is possible. For each registered object there is debug of public properties, there is debag of public methods with indication of parameters, default values ​​of parameters and even DOC / ** comments to methods / object / properties.
Bottom line: at this moment, Quicky has the richest debager I've ever seen. This is a display of DOC and display of objects and display of the place of registration of variables.
')

Optimization


{math equation = "x + y" x = $ height y = $ width}
I do not know what is your attitude to this design, but now you can use it without worrying about performance. The string will be compiled into the expression and not tortured through eval
in the case of {math equation = $ eq ....}, the torture function will be called as before from regularizers and eval.
here, of course, it is more convenient to use the syntax {? $ newVar = $ a + $ b}

Compatibility


Despite the fact that this is not written separately, steps have been taken on additional compatibility between kviki and templates written for smarty. At the moment, the vast majority of templates written for Smarti are processed by Kviki unchanged. For those who have not tried Quicky, this is a reason to try, now you can definitely write templates that are compatible with both template engines.

Localization of variables


Perhaps this is also a key point. The main difference between Kwiki and Smarti is that Kwiki uses a common variable space for all templates / subpatterns. Now it is possible to use local variables.
Briefly, the syntax is:
{ local $ i = 0} - enters the local variable $ i into the template
{ global $ i } - returns the pointer $ i to the global variable $ i
{ import $ i } - imports the $ i variable from the global space to the local one, that is, the $ i triggered by the value global $ i appears in the local space

{ declare name = 'depart_scopes'} - this line redirects all calls to local variables
{ declare name = 'depart_scopes' value = 0} - this line redirects all calls to global variables

in practice, this means that you can now write something like:
 {$ info} - displays the declared value.
  {declare name = 'depart_scopes'}
      HERE code in which you can use variables without fear of overlapping global values 
	  {if isset ($ quicky.request.a)} {? $ a = true} {/ if} - the $ a variable is local.
	  if you need to use global variables, then you need to import them
	  {import $ info}
	  {$ info} - derived $ info
	  {? $ info = "new"} we overwritten a local variable ($ info = {$ info}), but the global $ info remained as it was
  {declare name = 'depart_scopes' value = 0}
  {$ info} - displays the previous value.
 

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


All Articles