Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Creating block compiler function

 
Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
dpatterson
Smarty Rookie


Joined: 12 Apr 2013
Posts: 16

PostPosted: Mon Jul 22, 2013 5:03 pm    Post subject: Creating block compiler function Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4646
Location: Hamburg / Germany

PostPosted: Mon Jul 22, 2013 6:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
dpatterson
Smarty Rookie


Joined: 12 Apr 2013
Posts: 16

PostPosted: Mon Jul 22, 2013 6:27 pm    Post subject: Reply with quote

Thanks for the info.

As a note, I don't see any reference to the close version of a tag at
http://www.smarty.net/docs/en/plugins.compiler.functions.tpl.

But with this info I should be able to accomplish what I want.

Thanks again.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4646
Location: Hamburg / Germany

PostPosted: Mon Jul 22, 2013 6:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
dpatterson
Smarty Rookie


Joined: 12 Apr 2013
Posts: 16

PostPosted: Mon Jul 22, 2013 6:54 pm    Post subject: Reply with quote

I'm sorry. I don't understand what you mean about the $params array.
Could please expand upon that?

Thanks.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4646
Location: Hamburg / Germany

PostPosted: Mon Jul 22, 2013 7:08 pm    Post subject: Reply with quote

See http://www.smarty.net/docs/en/plugins.compiler.functions.tpl

As on any plugin attributes will be passed in the $params array.

Like {foo name='bar'} you will find 'bar' in $params['name']
Back to top
View user's profile Send private message
dpatterson
Smarty Rookie


Joined: 12 Apr 2013
Posts: 16

PostPosted: Mon Jul 22, 2013 7:14 pm    Post subject: Reply with quote

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. Very Happy
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 4646
Location: Hamburg / Germany

PostPosted: Tue Jul 23, 2013 5:59 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP