I'd like to have a dynamic title displayed at the top of my module page. Since hook_menu is predefined, how can this be accomplished? Should the hook_menu title be defined as empty (or left out) and replaced with custom text displayed? Or is there a way to change the title on-the-fly?

Thanks.

Comments

nevets’s picture

If you use the menu module can can do this directly for some menu entries. There is also a function called drupal_set_title() that can be used to set the page title. Depending on the details of what you want to do this seems possible.

johnhanley’s picture

Thanks, Nevets. drupal_set_title() did the trick.

Shame on me for not thoroughly checking the function list. Then again with over 1100 functions one can hardly blame me. Alphabetically sorting just doesn't cut it. They need to be grouped by type, list php.net.

For the record can you or someone demonstrate how this can be accomplished via hook_menu?

decon’s picture

Is there an example of how this could be done on an individual page?

Lets say I have a page that has a general title of "Bananas and their quirky ways"

but maybe I just want it to be called

"Bananas"

can I input some php code directly into the page post?

Would this also work with Nodes?

I wish there was an easy way to set Page Title alias to separate it from the title used as the Header in the page. I'm sure there is a hack but from reading through I am not sure if there is a simple and easy way to do it.

any info pointing me in the right direction would be appreciated, thanks!

decon

johnhanley’s picture

I was just asking if there's another way of accomplishing the same thing. I always like to know if there's more than one way of doing something.

merlinofchaos’s picture

Yes, you can insert PHP into any node if you've got privilege to use the PHP input filter (which should be limited to just administrators for security reasons).

Once that's done, you could enter:

<?php drupal_set_title("Bananas. Their Quirks. And You."); ?>

You can do the same thing via hook_menu by putting your menu declaration outside of the if ($may_cache) { } block; I'm not sure this is good practice, though. It may be advisable to do some kind of check to make sure the page currently viewed is the right one before changing the menu title. (And even so, from there I believe you can only change the menu title, which is inherited to the page title, if that makes any sense)

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]