Theming Drupal book hierarchies - drupal

I'm just getting round to converting our static HTML website to Drupal. Our website is currently structured into sections, each section having a header, then a list of sub-sections below (for an example see http://www.eurosafeuk.co.uk/services/).
This ties in very nicely with Drupal's "book" module, but I need to customise the display of child pages; by default they're printed as an unordered list of page titles, whereas what I need is to output:
A teaser image for each page
The page title
The page summary
I've looked through the .tpl files, and found that the children are stored in a $tree variable (already HTML formatted). My question is: where do I start if I want to modify this? Does anyone know of a pre-existing module that would do it, or do I need to dig into the code?

Instead of using the Book module which is specifically for a book structure, you might want to look into modules that are made for your case. I haven't looked very well but the Node Hierarchy module might be useful for you. . Here is an excerpt from its project page:
... allows nodes to be children of other nodes creating a tree-like hierarchy of content. The module offers:
1-Click creation of hierarchical menus
Hierarchical breadcrumbs
Automatic hierarchical urls using Pathauto (and token module)
(eg: q=aboutus/history/beginning).
Automatic creation of hierarchical menus if desired.
Optional Views integration.
Optional Node Access integration.
If you want to theme nodes in specific sections in different ways, it's probably a good idea to make separate .tpl files for every section. The way you name those .tpl files makes them applicable to nodes in a certain section.

Get the devel module, and turn on theme developer. This will tell you the template or function which is used to build the HTML and what templates you can create to override it.

Related

Drupal page content

I'm new to drupal and reading through docs, but hoping to get an explanation for something.
I have a page called page--type-home-page.tpl.php.
Part of this page prints render($page['content'])). I want to remove something that is rendered as part of the page content from the page, but don't understand where this comes from and where/how to look.
Thanks!
Assuming you're talking about Drupal-7
Well the $page['content'] contains a string, which is a rendered version of what's injected into the content region of your theme.
By default, the only block in this region is the "Main page content" block that is generated by the Drupal core. Many things can generate this content but it always pass through the menu API. For instance, if you're viewing a node, the URL used is: node/12. The node module declares a menu entry for node/%node, this menu entry contains a callback function that will render whatever the module wants to render. The module, then, may use different strategy to render it's content from a simple function to a complex imbrication of templates.
The key to alter what's in the box, sorry, what's in the $page['content'], is to know what is rendered and to understand how it's rendered.
If it's a node, first you want to look if you can achieve your goal through the display settings of the content type. admin/structure/types/manage/page/display: And this is true for all entities (users, comments, taxonomy term etc.) Because this is the first thing the module of these entities will put together when they'll try to render your content.
If this is not enough to achieve your goal, you can look into the module that renders the path to see if it hasn't a .tpl.php. You'll be able to re-use it in your theme. You'll want to copy/paste the file in your theme and edit it.
If the module do not have a tpl file to override, try a template suggestion: here's a list from Drupal.org
Ex: node--type.tpl.php
If all this doesn't satisfy your need, you'll have to dig into preprocess functions; Those functions allow you to modify what's in the variables passed to .tpl.php files. That's a little more advanced and I recommend you to read this previous stackoverflow question/answer
Simply, don't use that $page['content'] which prints all content, but place your custom template code instead and print separate field values where you need them like:
<?php print render($content['your_field_name']); ?>
https://drupal.stackexchange.com/questions/30063/how-to-print-fields-in-node-tpl-php
If you want to do just simple styling, like excluding some field you can use content type display options like mgadrat explained, but if you want to use some complex styling, with totally custom html this solution is easier.

Drupal: How to override Advanced Forum topic list for one specific forum term

I'm using Drupal 7, and have the Advanced Forum module installed.
However, I want to show some Ubercart products in one section of the forum, called the Marketplace to make them more visible, and since users will be able to add their own products.
However, obviously in this section I want to show the forum topic list differently, including the price and other such fields.
Is there an easy way that I'd be able to do this, perhaps using Views? I'm really at a loss for what to do.
You should be able to just create a new View with a page display that displays things like you want them and then set the URL for the view to be the URL that is currently being used for the forum listing you want to override, so that the links to it still work without any additional work.
First of all, you should override the page template for one specific term by creating a new page like so:
page__forum_TERMID
To go more into details about what you need to show in this custom page, you may need to install the Devel & Theme Developer modules.
With Theme developer you will be able to inspect your Drupal output on various parts of the page in order to find out either which preprocess function or which template it originates from.
With Devel you will be able to output some of the variables you may need to act upon in order to generate your custom layout.
I would advise you to look at the implementation of the [Advanced Forum More Styles](http://drupal.org/project/advanced_forum_more_styles) in order to see how you could create your own Advanced Forum Style, which basically means a folder where you can store the various custom templates that will override the Advanced Forum templates.
Recently, I did something similar to what you're looking to achieve, I created a custom module to hold the various preprocess functions and that module contained a styles folder which was declared like so:
function YOURMODULENAME_ctools_plugin_directory($module, $plugin) {
if ($module == 'advanced_forum') {
return 'styles';
}
}
If you look at the styles in the AF module, you will see that they only override a few templates, so you may have to find the template you're looking for in the base style such as the "Naked" style.

drupal replacing default nodes with views page

I have created a page view using field style to display a list of teasers as I want. fields configuration in views allows us to link the field to it's node. but what if we have created view for node detail page and want field to link to it's relevant view.
I had the same question, and after a bit of research this is what I've concluded:
The views module isn't intended to replace a default node view. I say this because of the level of difficulty involved in doing this and the lack of information on how to accomplish this. Ryan Weal has posted a way to accomplish this by editing your node template that doesn't look too difficult to accomplish, and here is the link.
However, it seems that a more popular solution, especially if you are like me and don't like to get into editing theme files. You can use the Display Suite module to effectively reformat the default node content as you would like.
I'm not sure if I understand you properly, but it sounds like you are wanting to display a view in a page view of a node?
In order to do this, you could:
create a small module, using hook_nodeapi() or one of the D7 replacements for this function in order to insert the output of the embedded view into this page's content, by conditionally adding a $content element when the node is of the appropriate id
or (easier, but requires allowing input type PHP) embed the view right on the page.
http://thedrupalblog.com/embedding-view-drupal-6-using-views-embed-view for information on embedding views

Drupal: Template Files, Modules and Content Types for Advanced Theme

Intro
I am in the process of trying to convert my first HTML/CSS design into a theme for Drupal. I have used ModX for quite a few designs and appreciate the ability to create different page templates and custom variables to be assigned to those templates. However I seem to be having some issues making the transition.
The site I am working on theming in Drupal is for a real estate agent. Each page/section will have a different set of content associated with it and will need to display only that content. For example, there will be a page for current listings, each of which will be formatted by a custom content type. However, when I call the content on the home page (or on other pages) I do not want to see this listing data.
Layout
The layout of the site and the regions associated with each page/section is as follows:
Home
Spotlight
Featured 1
Featured 2
About
Spotlight
Bios - Profiles of each agent (each will be a node with name, contact info, pic, etc) listed on the page; multiple nodes listed
Sidebar
Listings
Spotlight
Listings - Profiles of properties (each will be a node with locations, basic info, pic, etc) listed on the page; multiple nodes listed
Sidebar
Services
Spotlight
Content - general paragraph text area
Sidebar
News/Blog
News/Blog Items - List of stories with summaries and links to full article
Sidebar
Each page/section will use the same header and footer.
Issue
I have done some reading on Drupal, custom content types (and CCK), Views, and Pathauto. However I have not been able to get a clear picture of how to put it all together to accomplish what I am attempting. What I really would like to know is which modules to use, how best to use them, which elements I need to use where, and what template files I should be using to theme the elements I need to use. Any help or reference to useful resources would be much appreciated.
This is a rather general question, and your description is a kind of vague on important distinctions like page vs. site section vs. page region. That said, some general advice: start by installing the admin module. Then get all your content generally in the right places with someone else's theme, e.g. Garland, before you start doing any of your own theming. You should be able to get pretty far without touching code. Use CCK to define your content structure. You should already have a type for page and it sounds like you'll want to add a type for feature, bio, listing, and blog post. Depending on the details, you may need to add some additional field modules, e.g. if you have images, you'll probably want the imagefield module.
Once you have the content types defined, configure pathauto, and start adding content.
Once you have some content, you'll want to create some lists of it with views. You may want to start with the simpleviews module, as the views UI can be overwhelming. Save your views as block display, and then use the blocks admin to put the in the right page region, and configure them to show up only on the right pages.
At that point, you'll want to start controlling how the individual items (nodes) look in different contexts. That's when you start theming. For that, I'd install the devel module, look at what other themes do, and call dsm() on any variables you don't understand to see what they look like.
You can generally get quick help with specific questions on the Drupal IRC channels.
The easiest way to do what you want to do may be to put your custom content in blocks and set the access settings for the blocks to be only on certain pages. So, for instance if you have content that you want to appear at /spotlight or /node/22 or such, you would just create a custom block (Site Building -> Blocks) and then in the settings, set the block to only show for that node.

Customize the way CCK Node Reference fields are displayed in Drupal

Node reference fields in Drupal are displayed as lists by default. Is there a way to change that?
I'd like to output them as JSON so I can create a fancy JavaScript visualization.
You can modify it in 2 ways: via custom module with function hook_form_alter or via theming (preprocessing form or templating form).
http://api.drupal.org/api/function/hook_form_alter/6
http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6
For AHAH: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html/6#ahah
Also, nodereference already have little ahah: "autocomplete" in field editing of custom node type.
Consider the Content Templates (Contemplate) module. Here is a quote about it (from the module's project page):
... allows modification of Drupal's teaser and body fields using administrator defined templates. These templates use PHP code and all of the node object variables are available for use in the template. An example node object is displayed and it is as simple as clicking on its properties to add them to the current template.
This module was written to solve a need with the Content Construction Kit (CCK), where it had a tendency toward outputting content in a not-very-pretty way. And as such, it dovetails nicely with CCK, adding a "template" tab to CCK content-type editing pages and pre-populating the templates with CCK's default layout. This makes it easy to rearrange fields, output different fields for teaser and body, remove the field title headers, output fields wrapped for use with tabs.module (part of JSTools), or anything you need.
But Content Template can actually be used on any node type and allows modification of the teaser and body properties before they go out in an RSS feed, search index, or are handed off to the theme. Additionally, ConTemplate can choose to add any files, images, or other media to RSS feeds as an attachment.
Templates are normally stored in the database but it is also possible to create disk-based templates which live in your sites directory and can be inherited across multisite installations in the same way as themes or modules.
Try the Custom Formatters module, simply make a custom formatter to render the node out exactly how you want it, then output the formatter to code or to a Feature for deployment.

Resources