Hi,
I'm trying to change the title of the menu item "View" on a node page.. I want to change the tab name to be the title of the node (with an ellipsis if it goes beyond a limit).. This means the title of the tab here will be dynamic.. I've tried using hook_menu_alter and tried to change the title of the menu item 'node/%node/view' with some code.. I tried 3 ways -- one, get the title using a query with arg(1), two, by page_get_title, and 3 by menu_get_object to get the respective node and then the title.. None of the approaches has worked for me.. If you guys know a quick solution, that would be wonderful.. I dont want to change it via tpl for sure..
PS: I've also tried hook_menu_link_alter but it did not work
Cheers, Mukesh
Ok, so a bad way is to write the following code in your template.php
function THEMENAME_preprocess_page(&$vars) {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = $vars['node'];
if ($node->type == 'XXXX') {
$vars['tabs'] = str_replace('View', $node->title,$vars['tabs']);
}
}
}
and it works but i would really want to know if there is a cleaner way to do it..
Cheers, Mukesh
On Thu, May 27, 2010 at 9:57 AM, Mukesh Agarwal mike4u4ever2001@gmail.comwrote:
Hi,
I'm trying to change the title of the menu item "View" on a node page.. I want to change the tab name to be the title of the node (with an ellipsis if it goes beyond a limit).. This means the title of the tab here will be dynamic.. I've tried using hook_menu_alter and tried to change the title of the menu item 'node/%node/view' with some code.. I tried 3 ways -- one, get the title using a query with arg(1), two, by page_get_title, and 3 by menu_get_object to get the respective node and then the title.. None of the approaches has worked for me.. If you guys know a quick solution, that would be wonderful.. I dont want to change it via tpl for sure..
PS: I've also tried hook_menu_link_alter but it did not work
Cheers, Mukesh
Hey.. that looks to me a perfectly valid way. You could try and use the 'themer' module from the devel family to check how else that can be done. A preprocess function in the template file is not a bad way either. I dont see you triming and adding an ellipsis in your code.
On Thu, May 27, 2010 at 10:24 AM, Mukesh Agarwal mike4u4ever2001@gmail.comwrote:
Ok, so a bad way is to write the following code in your template.php
function THEMENAME_preprocess_page(&$vars) {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = $vars['node'];
if ($node->type == 'XXXX') {
$vars['tabs'] = str_replace('View',$node->title, $vars['tabs']);
}
}
}
and it works but i would really want to know if there is a cleaner way to do it..
Cheers, Mukesh
On Thu, May 27, 2010 at 9:57 AM, Mukesh Agarwal <mike4u4ever2001@gmail.com
wrote:
Hi,
I'm trying to change the title of the menu item "View" on a node page.. I want to change the tab name to be the title of the node (with an ellipsis if it goes beyond a limit).. This means the title of the tab here will be dynamic.. I've tried using hook_menu_alter and tried to change the title of the menu item 'node/%node/view' with some code.. I tried 3 ways -- one, get the title using a query with arg(1), two, by page_get_title, and 3 by menu_get_object to get the respective node and then the title.. None of the approaches has worked for me.. If you guys know a quick solution, that would be wonderful.. I dont want to change it via tpl for sure..
PS: I've also tried hook_menu_link_alter but it did not work
Cheers, Mukesh
-- [ Drupal support list | http://lists.drupal.org/ ]
I guess you are right.. i just wanted my hook_menu_alter to help me out here but turns out that it cannot support dynamic titles.. I can always replace "View" by "Take a look" from the hook but dynamic part does not work.. Plus it would have been good if menu would not get cached by default..
Yeah, i've added the ellipsis in my code, forgot to copy that here..
Cheers, Mukesh
On Thu, May 27, 2010 at 10:49 AM, sumeet pareek positivecharge@gmail.comwrote:
Hey.. that looks to me a perfectly valid way. You could try and use the 'themer' module from the devel family to check how else that can be done. A preprocess function in the template file is not a bad way either. I dont see you triming and adding an ellipsis in your code.
On Thu, May 27, 2010 at 10:24 AM, Mukesh Agarwal < mike4u4ever2001@gmail.com> wrote:
Ok, so a bad way is to write the following code in your template.php
function THEMENAME_preprocess_page(&$vars) {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = $vars['node'];
if ($node->type == 'XXXX') {
$vars['tabs'] = str_replace('View',$node->title, $vars['tabs']);
}
}
}
and it works but i would really want to know if there is a cleaner way to do it..
Cheers, Mukesh
On Thu, May 27, 2010 at 9:57 AM, Mukesh Agarwal < mike4u4ever2001@gmail.com> wrote:
Hi,
I'm trying to change the title of the menu item "View" on a node page.. I want to change the tab name to be the title of the node (with an ellipsis if it goes beyond a limit).. This means the title of the tab here will be dynamic.. I've tried using hook_menu_alter and tried to change the title of the menu item 'node/%node/view' with some code.. I tried 3 ways -- one, get the title using a query with arg(1), two, by page_get_title, and 3 by menu_get_object to get the respective node and then the title.. None of the approaches has worked for me.. If you guys know a quick solution, that would be wonderful.. I dont want to change it via tpl for sure..
PS: I've also tried hook_menu_link_alter but it did not work
Cheers, Mukesh
-- [ Drupal support list | http://lists.drupal.org/ ]
-- Cheers Sumeet Pareek
-- [ Drupal support list | http://lists.drupal.org/ ]
Mukesh Agarwal wrote:
I guess you are right.. i just wanted my hook_menu_alter to help me out here but turns out that it cannot support dynamic titles.. I can always replace "View" by "Take a look" from the hook but dynamic part does not work.. Plus it would have been good if menu would not get cached by default..
This is untested but you should be able to use hook_menu_alter and add
'title callback' => 'check_plain' 'title argument' => array('My new title')
The issue over here is that when i use the hook, I do not get arg(1) or menu_get_object() to be able to retrieve the node.. My menu item is 'node/%node/view' so I would have ideally wanted to use menu_get_object but that does not really return anything.. retrieving the title of the node using arg(1) and then querying does not really sound a good idea to me..
Cheers, Mukesh
On Thu, May 27, 2010 at 5:36 PM, Earnie Boyd earnie@users.sourceforge.netwrote:
Mukesh Agarwal wrote:
I guess you are right.. i just wanted my hook_menu_alter to help me out here but turns out that it cannot support dynamic titles.. I can always replace "View" by "Take a look" from the hook but dynamic part does not work.. Plus it would have been good if menu would not get cached by default..
This is untested but you should be able to use hook_menu_alter and add
'title callback' => 'check_plain' 'title argument' => array('My new title')
-- Earnie -- http://progw.com
-- http://www.for-my-kids.com
[ Drupal support list | http://lists.drupal.org/ ]