开发者

How can you implement jQuery code in Drupal pages (for non-coders)

I notice that jQuery 1.2.6 is installed with the latest version of Drupal 6. But it's not called by content pages by default. Assuming I wanted to include a very simple jQuery code snippet (not a plugin, etc.) in a page:

I'm looking for a solution for non-coders. And while modifying php files is an option, it's my least desirable solution. Instead, I want to add in a script tag, pulling in the latest version?

I can imagine that it could cause problems we can't even anticipate down the road, but I've confirmed that it does work quite nicely on a single page (as of the current version, etc).

Is there another simple way to 开发者_开发百科enable jQuery by default, something that can be done with minimal coding?


Yep, including it in your .info file should work fine.

A cautionary note for future reference, however: If you eventually find you need a newer version of jQuery than Drupal core provides, don't just upload that newer version to your theme folder and stick a reference to it in your .info file. You'll find Drupal adds its old version of jQuery on pages where it thinks jQuery is needed, and you'll end up with two versions of jQuery on one page. Instead, install the jQuery Update module, and put a reference to the new jQuery file it provides into your theme's .info.

Also, for those who don't mind coding, a call to drupal_add_js() in a hook_init() or a preprocess_page function will get Drupal to add jQuery to the page.


Looks like I can direct them to modify the .info file in a particular theme to include jQuery.


Check in your page.tpl.php of your theme this code:

    <?php print $scripts ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜