Re: Writing an extension for HTML::Template - how to do it?

Dan Horne <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.html-template
Message-ID <1131495395.31997.17.camel@rdblin01>
On Wed, 2005-11-09 at 12:51, Webmaster Techcode.NET wrote:
> MessageNo need to send emails to both me and list (twice) I guess ?
> 
er, ok
> 
> Anyway - I already looked into that. It's what CGI::Application::Framework uses.
> But it's not what I need/want.
> 
> That way I can only call some run_mode (method) from current module (one that is outputing
> the template in the first place).  I would need to manualy add plugins to each of the module
> (or just in base module). 
> 
> 
> On the other hand, I could write an method in my base module (inherited by others). And implement
> that logic inside of him (require SomeModule, call some_run_mode in it ...).

I don't know how much flexibility you need. I have a limited number of
run modes that my templates embed so I just place them in my base class.
I guess you could import them into your namespace or perhaps other list
members have more elegant solutions - I'm sure that there is one though
> 
> 
> But all that would be similar like this:
> 
> <TMPL_VAR NAME="CGIAPP_EMBED('run_plugin','some_plugin','param1','param')">
> 
> I was hopping to avoid that ... and make it shorter/simpler as:
> 
> <TMPL_PLUGIN NAME="SomeName(param1, param2)">

Well, you can use a filter to make it whatever you want. I like

[% snippet="SomeName(param1, param2)" %]

because our designers like to distinguish between template tags and HTML
tags, and not using angular brackets make it easier for them

>   ----- Original Message ----- 
>   From: Dan Horne 
>   To: 'Webmaster Techcode.NET' ; [email protected] 
>   Sent: Tuesday, November 08, 2005 11:33 PM
>   Subject: RE: [htmltmpl] Writing an extension for HTML::Template - how to do it?
> 
> 
>   Hi
> 
>   Since you're using CGI::App, you should have a look at CGI::Application::Plugin::AnyTemplate - which will allow you to call a run mode with the H::T
> 
>    <TMPL_VAR NAME="CGIAPP_embed('some_run_mode', 'param, 'param')">
> 
>   Dan
> 
>     -----Original Message-----
>     From: [email protected] [mailto:[email protected]] On Behalf Of Webmaster Techcode.NET
>     Sent: Wednesday, 9 November 2005 11:16
>     To: [email protected]
>     Subject: [htmltmpl] Writing an extension for HTML::Template - how to do it?
> 
> 
>     Hello folks!
> 
>     Don't know if it's just me or documentation of HTML::Template::Extension isn't good. Eitherway, I can't figure out how to write an extenstion for it, that I need for my project. 
> 
>     I work with CGI::Application, and I wan't to be able to use (reusable) objects in my templates.
> 
>     For instance :
> 
>     <tmpl_plugin name="SomeName(param1, param2)">
> 
>     My filter would find SomeName module (Prefix such as MyApp::Plugin::SomeName) make an instance of it and call method - say named run. And place returned value instead of this tag.
> 
>     Think of it as another template file that is included but it has some processing ... That way I can create one module/plugin and use it througth whole site/application.
> 
> 
>     If I don't figure this out soon - I will have to give a shot to HTML::Template::Expr and register a function with it (<tmpl_var name="plugin(SomeName, param1, param2)">).
> 
>     Thanks.
> 




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.