I am printing out a finder instance with autocomplete element in page.tpl.php like so:
print finder_view(finder_load(3), 'block');

For the autocomplete suggestions box to show up I needed to either:

add the block created by the "Provide block" option
or
add drupal_add_js('misc/autocomplete.js'); to template.php

Why do I need to manualy add this automplete.js file to template.php when I am manualy printing out the finder instance through finder_view?

This talks about the same but issue was closed
http://drupal.org/node/624438#comment-2305098

Thanks in advance for any feedback on this

Comments

danielb’s picture

Why do I need to manualy add this automplete.js file to template.php when I am manualy printing out the finder instance through finder_view?

You don't have to do this at all, the JS will be automatically added. I tried it just now.

FYI, You might also want to check user_access('use finder') is TRUE before spitting that finder out.

Probably the best way to do this though is to enable the "provide block" option and use drupal's functions to display it as shown in the comments here: http://api.drupal.org/api/drupal/developer--theme.php/function/theme_blo...
The module is 'finder', and the delta will be 'finder_3' I believe.
This will do the access check, format the block correctly according to your site's theme, and allow modules that need to alter the block to do their job properly.

I dunno why you'd do this in page.tpl, just set up a finder region or use an existing region, and stick the block into it.

If anyone finds this post trying to stick a finder block into a node - try this cck/fields module: http://drupal.org/project/blockreference

danielb’s picture

Oh the JS doesn't get added in via page.tpl, I previously just output it in the body of a node.

I guess because at that point the $scripts variable has already been decided on and printed out.

That's just how it is I suppose, Drupal needs to know about this finder output before it hits the theme layer.

Keep in mind that depending on the configuration of your autocomplete element, namely the 'submit upon selection' checkbox, finder will need a different javascript file.

danielb’s picture

Status: Active » Fixed

Well that explains why you need to add the script manually, or perhaps why it's better to not print the finder out in page.tpl at all. You can decide what to do about that.
Adding the script manually probably also means you can't take advantage of js aggregation/compression and possibly other enhancements - not 100% certain on this.

undersound3’s picture

Hey DanielB,

Thanks for your reply;s, appreciated.
It makes total sense to let the module provide a block and put that in a region through /admin/build/block/list

The problem is, I am not seeing the suggest box (with possible results) showing up with my current theme.
Switched to Garland and it's showing up perfectly so....this is something I screwed up obviously within my theme.

Anyway thanks for you time. I am still trying to accomplish this
http://drupal.org/node/1072108

which I am getting closer and closer to.

Keep you posted
Undersound

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

danielb’s picture