1

I'm working through the second post in this thread, so I can call a custom method from jQuery. https://stackoverflow.com/questions/4834132/how-to-pass-jquery-variable-to-drupal-ajax

(I already have a html form, so the Forms API doesn't really help me)

The post mentions a menu_hook, but always describes the hook, as belonging to a module. I only plan on adding one method, so I don't really want (or know) how to create a module from scratch.

Is it possible to add the menu hook to my template.php, or another file which already exists?

  • 2
    Functionality belongs into modules, themes are for changing how things looks. So creating a module (which is very simple, as the answer from @Letharion shows) is the way to go. – Berdir Mar 26 '12 at 9:44
6

You should create your own module for your hook_menu. It's not hard or bad in any way. :) It's also near trivial.

in sites/all/modules/custom_module create two files:

custom_module.info with

name = My custom module
core = 7.x

custom_module.module with (copied from linked to question)

<?php
function custom_module_menu() {
  return 'my_custom_callback/%' = array(
    'title' => 'My Custom Callback', 
    'description' => 'Listing of blogs.', 
    'page callback' => 'my_custom_php_function', 
    'page arguments' => array(1),
    'access arguments' => array('access content'), 
    'type' => MENU_CALLBACK,
  );
}

And you have a new module with a hook menu entry. Replace core = 7.x with core = 6.x if you want this to work for D6 instead of 7. And replace custom_module everywhere if you call the module something else :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy