Drupal Answers Asked by JurgenR on December 8, 2021
I want to add a meta description to a custom module ‘mymodule’, but this doesn’t load as expected.
The problem is in the active trail, when menu_get_active_trail is called inside array 1 the router_path = node/% and the title is page not found.
How can the active trail be fixed?
This works on other sites.
function mymodule_html_head_alter(&$head_elements) {
// menu_get_object with load function at position 2
if ($myentity = menu_get_object('myentity', 2)) {
dpm(menu_get_active_trail());
$head_elements['meta_description'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'description',
'content' => $myentity->name,
),
);
}
}
First, you have to make sure that the active menu is actually set. In Drupal 6, we did this like this: http://echodittolabs.org/blog/2010/04/drupal-fails-set-active-menu-trail-causing-context-fail.
Next, clear the cache, and then refresh the page. Yes, dpm()
has a lag or something. If you see the right data, great.
My data was actually being cached as page not found, when actually it had set the correct data. Don't know why.
So, your debug info may show "Page not found" when, what is being rendered would be correct. The way you see if this is the case is by clearing the cache and refreshing.
This is for Drupal 6, but the principles likely hold for Drupal 7. Unfortunately, I doubt anybody rewrote the crufty old menu system. Too much AJAX and glitz.
Answered by Jeremy JOhn on December 8, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP