mohamnag
mohamnag

Reputation: 2883

Why use JsHelper for jQuery integration?

I was trying to integrate jQuery to use it for some effects in my site and I started to search for the solution of integrating in the best way. It simply came to my mind to write a helper which would get the selector of proper element and output the javascript code. Then I ran into the new JsHelper in cake 1.3 but I'm really having problems understanding the concept of JsHelper. I mean for sure each JavaScript block that I'm gonna write is more than one call to jQuery methods and many of them are also not transfered to JsHelper. So for what reason may I use the JsHelper? it would be much easier to write the javascript specified for my action inside a helper and use it simply as any other helper. The only thing which comes to my mind as a good capability is to use the caching and buffering options provided in JsHelper nothing more. Did I understood the JsHelper well or I have missed some points?

Upvotes: 1

Views: 630

Answers (1)

Leo
Leo

Reputation: 6571

FWIW, I never use any of the javascript helpers except to write the include, i.e.

<?php echo $javascript->link('aJavascriptFile') ?>

I'd be pulling my hair out trying to find out why some jQuery plugin wasn't working if it was all wrapped up in helpers.

You don't have to use helpers - they're there to help. Sometimes people go a bit crazy and start creating helpers for stuff that really doesn't justify the weight of extra code.

Just code it the 'old way' and keep your sanity.

Upvotes: 4

Related Questions