I have copied some code from Bartik and simplified to the following:
<div id="menu">
<?php echo theme('links__system_main_menu', array('links' => $main_menu)); ?>
</div>
This generates the expected HTML list - however I now need to override some of that HTML so I much prefer having 100% control of the output. I'm not sure I understand how or what to override, having read the following:
http://api.drupal.org/api/drupal/includes--theme.inc/function/theme/7
1. How do I create a custom template for the "main menu" only? I assume I need a template file named something like: links__main_menu.tpl.php
2. Secondly, this main menu actually links to sub-domains (which I entered as external URI). These menus work, but obviously no page data is loaded according to sub-domain (something I will figure out later and hack in) and the menu items don't change "active" status. So to solve this issue I wonder if it's possible to implement a function hook and check the sub-domain in the hook and set the proper flag accordingly. I am guessing I could do this in the template itself but to keep things clean I'd rather use a template for rendering and a hook_x() for activating the menu item based on the sub-domain selected.
Cheers,
Alex
Comments
A very different approach to
A very different approach to your second question: came up with it when I needed a slight color modifications for subdomain colors/style (served from single codebase). Add a server name as class to your body classes (in template.php):
Then you can use a CSS something like that:
Might be handy in other situations as well of course.
Cheers,
Andrey
Free and Premium Drupal Themes | Drupal Sites Showcase. Add yours! | My Blog
So your basically adding the
So your basically adding the sub-domain as a class to all elements which might be styled differently per sub-domain? That could be a useful of changing the background :)
Still confused over the template file naming convention though.
I'm asking the theme() funciton to load a theme function or a template with the name: links__system_main_menu
links__xxx as I understand allows Drupal to fall back to a default theme as opposed to an override I may provide. How do I name my template if my theme is called 'basic'
links__basic_main_menu???
Where does the "main_menu" come from? How would I use/call a template file called main-menu.tpl.php
EDIT | I am starting to think Drupal does not support template overrides for *everything* especially menus - seems function hooks can be provided but not templates???
Nonono, of course I don't add
Nonono, of course I don't add sub-domain class to all elements with this code. Only to body tag, i.e.
I'm not quite sure yet if there is a .tpl.php for menus in D7 at all. For overriding menus I use preprocess or override functions in template.php:
http://api.drupal.org/api/drupal/includes--menu.inc/group/menu/7
Cheers,
Andrey
Free and Premium Drupal Themes | Drupal Sites Showcase. Add yours! | My Blog
Digging through the theme.inc
Digging through the theme.inc file and reading the API on various theme_xxx() functions it seems to me that template override is not a default behavior, at least for menus. Seems I must use a function instead...BAH
Cheers,
Alex
Template.php is helpful for customize theme
You can customize your theme's some functionality in template.php
Some default functions are there in drupal. If you print the function argument, you will get full page details by array format.
You customize external module field also.
for eg:
We can change the user login text-field label if you written code for this in your theme.
Response to the first question. (Override main menu theme.)
Hi alex,
I am new in the whole durpal thing and I had the same question few days back. Here is the solution I found. Please correct me if I got something wrong.
HYPOTHESIS:
SOLUTION:
NOTES:
'function' => 'your_function_callback'
Response to the first question. A more elegant solution.
Hi, I am reporting back from the Drupal documentation trenches. ;-)
I found a more elegant solution to your first problem, here it is...
HYPOTHESIS:
SOLUTION:
NOTES:
Nice Solution
This is a very nice solution, exactly what I needed. Just a small change: $link['path'] should be replaced with $link['href'].
Cheers,
Pavel
Also a nice solution
it don't show the menu
Hello.
I'm using Drupal 7 and I trying to override the links__system_main_menu function, and I already make everything on this page but the menu is not showing at all.
here is the code I am using in the template.php
and this is how I try to call it from the page.tpl.php
print theme('Vida_links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'inline', 'clearfix')), 'heading' => t('Main menu')));
Can some one help me please.
Not 100% sure, but this
Not 100% sure, but this should work
Let Drupal prefix your theme name when using theme() function
I don't think you should include the prefix of your theme, i.e. you should call theme('links__system_main_menu' ...) and not theme('Vida_links__system_main_menu'...). When you are using the theme() function, you are proposing to Drupal a particular type of function, and asking Drupal to look through the possible functions of that name; this means that someone else can overrride even your function if they want to get ahead of you in the theme function chain. So, theme() looks for functions in an order like:
When it doesn't find one, it goes on and looks for the next in the list until it finds one which matches. Hence, you should not include your template prefix.
If you include your template prefix, then you should just call your function directly, e.g. print Vida_links__system_main_menu(...). This though is considered bad theming since you should never call your function directly, but always use the theme function to allow Drupal to go through the list of possible theme implementations in order.
I definitely recommend using the Devel Themer module, which always shows you the full list of possible called functions and called templates, together with which function/template is actually being used.
So I think your call should look like as follows:
drupalshrek
Answer for the question 1
I've read all the comments. And after that, I have succeeded.
template.php
continue in the same file
page.tpl.php or any order
luisnicg solution works
thanks for sharing
works / doesn't work
This works for me to the extent that the functions are being called and execute (verified using dpm(), then reloading page), but the array containing the main menu is then apparently re-worked further down the road and appears as before (does not contain the custom stuff I added.) In the meantime, I found a different way of adding a NAV element:
I found this at: Joshua Powell GitHub account