how to create channel based template callback

View: New views
3 Messages — Rating Filter:   Alert me  

how to create channel based template callback

by Wang Zi Feng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey Guys, first I am new to drupal development and try to learn everything about drupal by scratch. My questions might be easy to you but still hard for me, so any reply is welcomed and appreciated.

Recently, I am going to create a customize module that to show all the blog members with their avatars triggering by hook_menu ‘?q=blog’ path.

I write the code as what the drupal module development guide taught,  first to use hook_menu to route the path as well as the callback function, then use hook_theme to state the template, and then use theme() function in the customize function to call template, last is use template_preprocess function to create the variables before it pass to template file.

But I found, all the variables that passed to the template file was packed into ‘contents’ region finally and placed into the template file. In other words, I can’t change the variable into other region, so that let me create a fully customize template for a specific path.

For a clearer understanding of my problem:

For example, like the difference between page.tpl.php and page-front.tpl.php, the second one could be fully customized with regions.

 If I want to call page-blogmember.tpl.php trigger by ‘?q=blogmember ‘ to show all the blog avatars but with a fully customized region template, how can I do.  Like creating customized channel by ?q=video or ?q=game.

Thanks

Frank

Re: how to create channel based template callback

by andrew morton-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm not totally clear what you're trying to do but it seems like you
could use a preprocess hook (e.g. modulename_preprocess_page()) to
alter the 'template_files' variable that the theme system uses to find
candidate files. I'd suggest reviewing the code in
template_preprocess_page() to see how the list of candidates is
assembled.

andrew

On Mon, Sep 28, 2009 at 3:34 AM, wang zifeng <frank.zifeng@...> wrote:

> Hey Guys, first I am new to drupal development and try to learn everything
> about drupal by scratch. My questions might be easy to you but still hard
> for me, so any reply is welcomed and appreciated.
>
> Recently, I am going to create a customize module that to show all the blog
> members with their avatars triggering by hook_menu ‘?q=blog’ path.
>
> I write the code as what the drupal module development guide taught,  first
> to use hook_menu to route the path as well as the callback function, then
> use hook_theme to state the template, and then use theme() function in the
> customize function to call template, last is use template_preprocess
> function to create the variables before it pass to template file.
>
> But I found, all the variables that passed to the template file was packed
> into ‘contents’ region finally and placed into the template file. In other
> words, I can’t change the variable into other region, so that let me create
> a fully customize template for a specific path.
>
> For a clearer understanding of my problem:
>
> For example, like the difference between page.tpl.php and
> page-front.tpl.php, the second one could be fully customized with regions.
>
>  If I want to call page-blogmember.tpl.php trigger by ‘?q=blogmember ‘ to
> show all the blog avatars but with a fully customized region template, how
> can I do.  Like creating customized channel by ?q=video or ?q=game.
>
> Thanks
>
> Frank
>

Re: how to create channel based template callback

by Wang Zi Feng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Andrew, thanks for your instruction.

I tried what you suggested. by using modulename_preprocess_page() theme hook, different template page.tpl.php file could be implemented by different path request.

Could you also see the code for me, I wonder if any better way to get same result?

the hook_menu path is games, and it will invoke page-games.tpl.php when visit ?q=games link.

function showpath_preprocess_page(&$variables){

if(drupal_strtolower(arg(0))=='games'){
    $suggestions[] = 'page-games';
    $variables['template_files']=$suggestions ;

   

}
}

THanks for your kind help

Frank




2009/9/28 andrew morton <drewish@...>
I'm not totally clear what you're trying to do but it seems like you
could use a preprocess hook (e.g. modulename_preprocess_page()) to
alter the 'template_files' variable that the theme system uses to find
candidate files. I'd suggest reviewing the code in
template_preprocess_page() to see how the list of candidates is
assembled.

andrew

On Mon, Sep 28, 2009 at 3:34 AM, wang zifeng <frank.zifeng@...> wrote:
> Hey Guys, first I am new to drupal development and try to learn everything
> about drupal by scratch. My questions might be easy to you but still hard
> for me, so any reply is welcomed and appreciated.
>
> Recently, I am going to create a customize module that to show all the blog
> members with their avatars triggering by hook_menu ‘?q=blog’ path.
>
> I write the code as what the drupal module development guide taught,  first
> to use hook_menu to route the path as well as the callback function, then
> use hook_theme to state the template, and then use theme() function in the
> customize function to call template, last is use template_preprocess
> function to create the variables before it pass to template file.
>
> But I found, all the variables that passed to the template file was packed
> into ‘contents’ region finally and placed into the template file. In other
> words, I can’t change the variable into other region, so that let me create
> a fully customize template for a specific path.
>
> For a clearer understanding of my problem:
>
> For example, like the difference between page.tpl.php and
> page-front.tpl.php, the second one could be fully customized with regions.
>
>  If I want to call page-blogmember.tpl.php trigger by ‘?q=blogmember ‘ to
> show all the blog avatars but with a fully customized region template, how
> can I do.  Like creating customized channel by ?q=video or ?q=game.
>
> Thanks
>
> Frank
>