View previous topic :: View next topic |
Author |
Message |
dpatterson Smarty Rookie
Joined: 12 Apr 2013 Posts: 16
|
Posted: Mon Jul 22, 2013 5:03 pm Post subject: Creating block compiler function |
|
|
Question one: Is it currently possible to create a block compiler function (e.g., {myTag}...{/myTag}) with Smarty 3?
Question two: If so, where can I find documentation and/or examples of how to do so?
There are some things that I would definitely like to implement as compile-time blocks rather than run-time blocks.
Thanks in advance. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Jul 22, 2013 6:18 pm Post subject: |
|
|
For the opening tag {mytag} create compiler.mytag.php and for the closing tag {/mytag} compiler.mytagclose.php
See http://www.smarty.net/docs/en/plugins.compiler.functions.tpl
To grab the content between the tags you must start an output buffer in the opening tag and and end it in the closing tag. |
|
Back to top |
|
dpatterson Smarty Rookie
Joined: 12 Apr 2013 Posts: 16
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Jul 22, 2013 6:46 pm Post subject: |
|
|
We know that the current documentation is poor. It's alreday on our Todo list.
Another note:
If you pass parameter the $params array does contain precompiled code ready to be included into the PHP code of the plugin.
If you pass a boolen true or false it's passed as string 'true'/'false'.... |
|
Back to top |
|
dpatterson Smarty Rookie
Joined: 12 Apr 2013 Posts: 16
|
Posted: Mon Jul 22, 2013 6:54 pm Post subject: |
|
|
I'm sorry. I don't understand what you mean about the $params array.
Could please expand upon that?
Thanks. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
|
Back to top |
|
dpatterson Smarty Rookie
Joined: 12 Apr 2013 Posts: 16
|
Posted: Mon Jul 22, 2013 7:14 pm Post subject: |
|
|
Ah. Got it.
Yep. I've already run into the parameters as strings thing.
Generally speaking, it seems to make things much easier in compiler functions.
Thanks for all of your help. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Jul 23, 2013 5:59 am Post subject: |
|
|
Anyway do you have a good reasion why you need to use compiler plugins instead of normal plugins?
The generated code of compiler plugins may be depending of the internals of Smarty which could change in future releases. (There will be some major changes in the upcomming major version 3.2 I'm working of)
Compiler plugins should be the last resort.... |
|
Back to top |
|
|