0

In my site I have a menu array that is printed in my page via drupal_render function.

I checked the array via krumo()* function and I found each item (link) has a property names '#theme' with value 'menu_link__main_menu'

If I use function theme_menu_link() in template.php (in theme folder) it will change all menu items but I don't want to change the theme of all menus. I want to change only specific item theme function.

So before using print drupal_render() function, I changed the #theme property of my selected link item directly.

For example

$menu_array[218]['#theme'] = 'custom_theme_function';

** 218 is the key of one of the link item in menu_array

but in this step, I don't know how should I define custom_theme_function in my theme template.php

I defined THEMENAME_custom_theme_function ($variables) {} in my template.php * THEMENAME is replaced by name of my theme

but it doesn't work. I don't know if I want to set a custom theme wrapper for specific menu items, How can I do that?

  • You also need to implement hook_theme and declare your theming function to Drupal. Otherwise it will skip your theme override because the function doesn't exist (as far as Drupal's concerned) – Beebee Jan 2 '14 at 15:32
  • You mean I should create a module for that? – Mehrdad201 Jan 2 '14 at 15:37
  • Nope you can implement it in your template.php: "Register a module (or theme's) theme implementations" – Beebee Jan 2 '14 at 16:11
  • I found that my problem is related to theme function registration because In Log section I see this alert " Theme hook custom_theme_function not found." Can you guide me how can I register my theme function in template.php – Mehrdad201 Jan 2 '14 at 16:23
  • Ok. I made some progression in my issue. I could register my custom function via this code: #### function blue_theme() {return array('custom_theme_function' => array('variables' => array()),);} #### and function work. but variables is null in calling function. I don't know what should I put in front of variables to access menu item. – Mehrdad201 Jan 2 '14 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.