Drupal 6: Drupal Themer gives same candidate name for different type of content types - drupal

I'm a drupal newbie...
I have different type of contents like News, Events, etc. and their content is different. News detail page has title-content text-date. but Events detail page has title-date-content text-location-speaker-etc. So I need different layout page for these different types. So, I enabled Drupal Themer to get a candidate name. for events page, it gave me page-node.tpl.php and it gives same for News page as well :( how can I separate these pages? I expected sth like page-event-node.tpl , but no... :/ Drupal Themer also give unique candidate name for event page like page-node-18.tpl.php but it doesnt mean anything since I can not create a general layout for all events by this node name. :(
Appreciate helps so much!! Thanks a lot!!!

While using different node.tpl.php files as suggested by monkeyninja (+1) would be the 'normal' way, you could add the functionality you want by adding page template suggestions based on node type yourself, in a preprocess_page function within a custom module/theme:
function yourModuleOrTheme_preprocess_page(&$variables) {
// If this is a node page, add a page template suggestion based on node type
if (isset($variables['node'])) {
// Build the suggestion name ('.tpl.php' suffix will be added by the theming system)
$suggestion = 'page-type-' . $variables['node']->type;
// Add to end of suggestion array, thus keeping the fallback to other suggestions,
// if this specific version is not implemented by the theme
$variables['template_files'][] = $suggestion;
}
}
With this in place, you should be able to add e.g. a 'page-type-event.tpl.php' file, which should be used for all event node pages.
(NOTE: You'll need to trigger a rebuild of the theme registry after adding that function to get it recognized by the system)

I'm not familiar with Drupal Themer, but a slightly different approach would be to work with the node templates to style the content and use something like the excellent Context module (and possibly Panels module) to change the layout of any additional information on the page (eg the blocks).
To theme the different content types using node templates, just create templates based on node.tpl.php in the form node-content_type.tpl.php. So you'd have a template for your events nodes called node-events.tpl.php.
You could then define a context using the Context module that reacted when a page of the events content type was displayed and select which regions/blocks you wanted displayed.

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 7: Add view to content type

I've been making a template for a particular content type, but just ran into a problem: I need to embed a view into the content type.
I am aware this can be done via several different methods, but I don't see one that fits exactly my needs:
I need the view added automatically for all pages of that content type.
Using blocks in a region is not an option, as I want to avoid defining a region in the middle of a page that should only be available for a specific content type.
Translatable label.
Possibility to freely apply a template to all fields in the content type (excluding the embedded view).
I tried doing it via page layout (Panels) and simply adding node content fields and the view to my layout regions, but then I get another problem: I can't style my content fields without doing something that seems a bit over the top:
Currently I have about 20 different content fields in the content type that are wrapped in HTML and styled in my template file. I have a translated label for each of these in the template file. From what I can tell I'd have to add a template for each of the panes containing content fields to add my translated labels and HTML needed to style each field.
I'm not really fond of making 20 templates, 20 theme hook suggestions to get the templates to work and 20 regions in the panel layout just to get a view inserted in the content type.
Am I doing something terribly wrong here? Any suggestions?
You may want to try the Viewfield module or similar modules (search for "view field" or "view reference").
If you are doing something more complex like changing/filtering the view based on some value in your content type, then you may have to use Viewfield module in combination with something else that will help fill in the filter values.
I've never done something like this before so I'm not sure exactly what module combination would work but Rules or Computed Field come to mind as possible helpers.
You have to use "views node field" http://drupal.org/project/viewsnodefield, after installing this module you have to select the "Node content" in the display (like blocks,page). then click the add display. if you want to display the content like this page http://www.richtown.ae/?q=content/arabian-ranches then you have to download the views_galleriffic module and install it and choose the style option "Galleriffic Gallery". You can choose the content type by using the filter in the views.
That's it cheers
i implemented this in my website richtown.ae
if you still unclear please send me the email social#richtown.ae i will reply you & ready to help you we can share information
i am using this module in drupal 6.
I resorted to using the EVA module ( http://drupal.org/project/eva ).
In addition to Woodgnome's answer
Let's say you have a content type named 'Product'
You want to attach a view to it.
Here are the steps using the eva module :
On your view edit page :
Section Displays
+Add : Eva field
Section ENTITY CONTENT SETTINGS
Entity type:Node
Bundles:Product
That's it, going to a node product type will now display the view

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

How can I show a certain type of contents on a specified page with Drupal 7

When I create a content type, I want to show all the posts of this content type on a page, I have to use view module. I don't like that.
Can I just specify the page and url when I create the content type?
But there is only one option, only front page. Can I change that? Hope you guys can tell me.
The views module is one of Drupal's killer features, you might want to reconsider writing it off completely.
Anyways, if you want to display all nodes of a type, you will have to code this yourself in a custom module. This means you will have to write some SQL, load the nodes and render them in a list. In this example you could use the EntityFieldQuery class to construct the query instead of writing the SQL yourself.
The end result will not be much different than what views will do for you, only difference is that you will need to create all of this with code in a module, instead of just setting this up in the Views UI.
I agree that views is a powerful tool that you shouldn't count out, but if you're set against using it (i refuse to use it on 2 of my sites purely due to overhead), You could use taxonomy instead. The taxonomy module already has a views style list for each term, I used this to achieve something similar to what you're looking for:
Set up a vocabulary whose terms match your node types and note the vid
add a hook_node_insert into your module file:
mymodulename_node_insert($node){
$terms=taxonomy_get_tree($my_vid); //where $my_vid == the vid of your vocabulary.
foreach($terms as $term){
if(strtolower($node->type)==strtolower($term->name)){
$items=array((array)$term);
$field['storage']['type']='field_sql_storage';
taxonomy_field_insert('node', $node, $field, null, null, $items);
}
}
}
After that you just need to add menu links pointing to your taxonomy page. Just as a note, I render all of my lists that I don't use views for with my own custom functions so I'm not sure what limitations this method might present.

Drupal 7- How to make a custom module for only front page?

so..I created page--front.tpl.php in my theme directory and it works fine.
now, how do I make a variable that can be used in the page--front.tpl.php?
I can write my php codes inside page--front.tpl.php, but I think there is a better way.
added:
on the front page, I am going to query video and news nodes ONLY. That is why I want to make a new module for only front page.
any suggestions?
I'm not sure what you are trying to achieve here, but OK. You have two options: one is what you're doing now. Write your custom PHP in page--front.tpl.php and you'll be fine. The other is ditching the file and working only with page.tpl.php.
The variable $is_front tells you whether you're on the front page. You can write custom PHP in a conditional block: if ($is_front) { ... }.
Also, you can create a custom block (a view, perhaps, depending on your needs) and set its display restrictions to "only on the listed pages" - and list there. You'll have a custom view loaded only on the front page.
All you need to do have a custom front page is configure your front page in the site information settins (admin/settings/site-information in D6).
Creating a module to display that content is then a completely different thing.
What I would really suggest is looking at Views if you don't know it already. That allows you to build lists of things (nodes, users, ...) and expose them as pages, blocks, rss feeds and much more. You can create a list of nodes with types video and news, expose that as a page and then just point your front page to the path of your view.
you might try using the views module to create your list of videos and nodes. You can set a views page to be your homepage in the site settings.

Resources