Passing data between Drupal module callback, preprocess and template

Posted by rob5408 on Stack Overflow See other posts from Stack Overflow or by rob5408
Published on 2011-02-02T22:53:56Z Indexed on 2011/02/02 23:25 UTC
Read the original article Hit count: 238

I've create a module called finder that I want to take parameters from a url, crunch them and then display results via a tpl file. here's the relevant functions...

function finder_menu()
{
    $items = array();   
    $items['finder'] = array(
        'page callback' => 'finder_view',
        'access callback' => TRUE,
    );
    return $items;
}

function finder_theme($existing, $type, $theme, $path)
{
    return array(
        'finder_view' => array(
            'variables' => array('providers' => null),
            'template' => 'results',
        ), 
    );
}

function finder_preprocess_finder_view(&$variables)
{
    // put my data into $variables
}

function finder_view($zipcode = null)
{
    // Get Providers from Zipcode 

    return theme('finder_view', $providers);
}

Now I know finder_view is being called. I also know finder_preprocess_finder_view is being called. Finally, I know that result.tpl.php is being used to output. But I cannot wrap my head around how to do meaningful work in the callback, somehow make that data available in the preprocessor to add to "variables" so that i can access in the tpl file.

in a situation where you are using a tpl file is the callback even useful for anything? I've done this in the past where the callback does all the work and passes to a theming function, but i want to use a file for output instead this time.

Thanks...

© Stack Overflow or respective owner

Related posts about php

Related posts about drupal