Hey all!
I'm entirely new to Drupal but am familiar with PHP, CSS and the CMS concept so I've been converting a site build into a Drupal 7 Theme.
My main question is: I've created a custom menu via the admin's 'Structure' tab and named it 'Footer Links'. Is there a specific PHP code I can use within my template's page.tpl.php file to echo out the menu called Footer links within li tags? Similar to how this outputs my main menu?: print theme('links__system_main_menu', array('links' => $main_menu, 'attributes' => array('id' => 'main-menu', 'class' => array('links', 'inline', 'clearfix'))));
It says the 'URL Path' is 'menu-footer-menu'
Other areas that would be extremely helpful for any direction:
1) My site's sidebar has 'buckets' of information that include simply a title, image, and description. I created a new content type called 'homepage bucket' (machine name 'homepage_bucket') with the fields: Title, Longtext, Image. How could I edit my page.tpl.php to echo out each node of the type 'homepage_bucket' while controlling the format of each field? For example:
<span>Title here<span>
<div>Image here</div>
<div>Longtext value here</div>
2) My site has an interior page template and a homepage template. What's the best way to define that the homepage uses template A and all other pages use template B?
Thanks for any help.. I'm sure these are obnoxious questions.
Comments
The easiest way to create and
The easiest way to create and control lists of content (such as the homepage list of nodes) is to use the Views module, you can create a "node view" of a particular content type and set this to be the front page (give it a path, then change the front page path in Site Information settings). There is plenty of information on the web about using Views - its one of the most popular Drupal modules.
If you want brutal control over all markup of fields then override field.tpl.php and remove all the HTML from it (hint - the core field.tpl.php file is in the Fields module directory).
You can also access raw output via granular variables such as:
$content['field_name']['#items']['0']['value']Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Display a custom menu
Here's how to display your custom menu:
In
template.php, set the menu variable:Then in your page templates, you can theme them like this:
Thank you for posting this
Thank you for posting this code. I really appreciate the time you took to post this. It was a bit unclear to me, and took some figuring out. Below additional information that I needed to understand in order to get this to work.
This works in Drupal 7.
If I understand correctly the way to understand the variables and use them is as follows?
1. In the backend go to the menus page. This is on: Administration -> Structure -> Menus
2. Click the edit button of the menu you want to use. If we choose the main menu we should now see in the URL: admin/structure/menu/manage/main-menu/edit. Where 'main-menu' is the name of the menu.
3. In the code above the name of the menu will occur in two variations:
We will call these respectively:
4. Now let's take a look again at the above code example.
In template.php, set the menu variable:
Then in your page templates, you can theme them like this:
Where the array variables 'id' and 'class' render the id and class for the unordened list (ul) the menu is in.
So:
Renders:
In conclusion:
Don't forget to clear your cache.
Use the opening PHP tag (
<?php) and closing PHP tag(?>) only if needed.Maybe we can work together on this, and get a clear to understand piece of code and documentation tying up any loose ends, and then enter it into a documentation page?
Update: Disregard the previous post
So, as it turns out after further reading the above way is apparently not the proper way to do this in Drupal 7.
Also the above code will only print the first layer of links, and not the children.
Apparently we're also supposed to use render now instead of the theme function.
Adding this to your theme will print a menu tree, but I'm not sure this is the proper way:
Is someone willing to make a definitive writeup of this? If you want to sit down and work together on this just let me know, and I'll help where I can.
I see so many parts of code snippets, and comments that it worked as well as comments that it didn't work, that I can't make heads or tails out of how it is supposed to be done.
From what I gather:
I've opened up a book page to build a documentation page on this, if you know how to do this the proper way please write it down so we can all save some time on this in the future. The book page can be found at How To Do Theming Examples Made Simple in Drupal 7. You can then add a child page for the subject.
Thank you for your participation! :-)
Edit:
Started a support issue How to display a menu in a template file?
If I may make the suggestion we consilidate efforts there on working on the issue before adding it to the final draft of the doc page.