[Catalyst] question from tutorial - does creating HTML in a
controller using HTML::Widget violate MVC?
Perrin Harkins
perrin at elem.com
Wed Dec 6 02:39:56 GMT 2006
Nilson Santos Figueiredo Junior wrote:
> On 12/5/06, Perrin Harkins <perrin at elem.com> wrote:
>> It can be really easy to add custom view code to TT templates. You can
>> immediately load any class and just call it:
>>
>> [% USE MyView %]
>> [% MyView.method(arg) %]
>
> Yes, but you'd need to manually use the correct class in every
> template and then call the appropriate method. This can be automated
> for the general case.
You can just add it to your TT configuration, which is probably set in
your view class. It's the "PLUGINS" option to Template->new().
>> Or you can pass a sub ref to the stash with your data and just call it:
>>
>> [% sub_ref(arg) %]
>
> Yes, but this sub ref would need to be created somewhere else, which
> would probably end up being at the controller, which is wrong.
Or, again, you could do it in your view class.
>> There's no need to do anything special for TT or make a "plugin" unless
>> you want to do something that requires access to the TT internals.
>
> By plugin, I meant anything that is called Template::Plugin::* and can
> be USEd inside a template (since [% USE Module %] will map to
> Template::Plugin::Module).
That's what I'm saying: it does not need to be called Template::Plugin::
or inherit from any Template module in order to use it this way. Check
out the TT docs for the USE directive and the LOAD_PERL and PLUGIN_BASE
config options for more details.
- Perrin
More information about the Catalyst
mailing list