I have searched the forums for "call function", and get a lot of results about "call to undefined function" errors, and I have searched the Handbook, but could not find anything about using functions in static pages - just about how to create a module or develop Drupal itself.

What if I want to call a module-defined function from within a php static page?

I want to put a taxonomy_browser (like what you get if you install taxonomy_browser.module then go to yoursite.com/taxonomy_browser) on a layer in a static php page.

I've tried putting "taxonomy_browser_overview" in there, and "requiring" the module. It recognizes the function, but gets stuck parsing it a few lines down, when it hits functions in the module that it says are undefined. What else do I have to include?

Thanks!
Ellen

Comments

javanaut’s picture

When you say "php static page", do you mean a Drupal node of type "page" or do you mean a "mypage.php" where you're including the code?

If it's a drupal page node, then enable the module and call the function as you described (make sure to surround it with <?php and ?> and specify the "PHP code" format).

If you're trying to execute code from a module from outside the scope of a drupal node, then there's quite a bit more work involved. You'll have to also include all of Drupal's core libraries. I haven't tested the following code, but I'm guessing it would look something like this:

include_once 'includes/bootstrap.inc';
include_once 'includes/common.inc';
print(taxonomy_browser_overview());

If you felt like digging through the code, you could probably reduce this down a bit to only include the drupal code being referenced.

EllenM1-1’s picture

I am using a drupal page node, but it only works when I use the includes as shown in the example above, with the addition of including the taxonomy_browser.module.

However now I have a conflict with the module, I think, because I am getting headers already sent errors. But we're getting closer!!

http://thedesignspace.net

Steven’s picture

The PHP nodes function was made more flexible in 4.5. In 4.4, you must return all content.

EllenM1-1’s picture

moshe weitzman’s picture

glad you got it working.

EllenM1-1’s picture

If you use the form that is in the "More Choices" tab, you get the search form at the end of the results. This is really bad, because it is in an absolutely positioned layer, and shows up on top of the results. I don't want the form to show up again!

I did manage to eliminate it partly - if you call the form instead by clicking "Category Browser" in the gray navigation column and search for anything, the form does NOT show up again in the results page. I don't know why this is - can't understand enough of the way the code works to figure this out.

Can anyone help me with this?
Also I would like to restrict the results generated by the "More Choices" version of the form to "Story" automatically, if possible.
http://thedesignspace.net