Drupal themeing is very easy and logical, but there are still a lot of questions at drupal.org and stackoverflow.com and other resources about how to do this and how to output that. Today, I will review and answer three most common Drupal Theming Questions.php
Here are the most common Drupal Theming Questions:node
This one was my first question when I was developing my first Drupal website. I wanted to put Drupal comments in a separate tab, but comments in Drupal are being outputted automatically in the bottom, so you can’t change the place of its output until you use this code:web
if (function_exists('comment_render') && $node->comment) {
echo comment_render($node, $node->cid);
$node->comment = NULL; }
A recommended place for putting this snippet is of course node template file which is node.tpl.php or node-type.tpl.php, but actually, you can put this snippet into any .php file and output comments for a passed through node. Just make sure that you have a proper $node loaded.less
In Drupal 6 default themes, we have annoying label above search-box which says: „Search this site」. It is absolutely useless label and I can only guess why did they include this one in Drupal 6, but we can easily get rid of it just following these steps:post
a) To remove label from theme’s main search form (which is called by $search_box):this
In your selected theme’s folder, edit or create (if it doesn’t exist) file named: search-theme-form.tpl.phpand add the following code to it:code
$search["search_theme_form"] =
str_replace(t('Search this site:'), '', $search["search_theme_form"]);
print $search["search_theme_form"];
print $search["submit"];
print $search["hidden"];
b) To remove label from block’s search form (which is called in a search box block):orm
In your selected theme’s folder, edit or create (if it doesn’t exist) file named: search-block-form.tpl.phpand add the following code to it:three
$search["search_block_form"] = str_replace(t('Search this site:'),
'', $search["search_block_form"]);
print $search["search_block_form"];
print $search["submit"];
print $search["hidden"];
if (isset($search['extra_field'])):
print $search['extra_field'];
endif;
If nothing changed - flush theme cache after implementing these changes.ip
Views are very popular nowadays in the Drupal world and nearly no site can be done without implementing Views more or less. One of the most common questions connected to views is how to output them on any desired Drupal page in any desired place? SIMPLE, just put this snippet where you want the View to output:
print views_embed_view('viewname', 'default', $arg);
Viewname can be easilly seen on a Views list page, just copy it there and paste instead of ‘viewname’,‘default’ is a default mode of the ‘viewname’ view. $arg can be empty or you can pass there ‘viewname’arguments (depends on what arguments your View uses).
So here are three most common Drupal themeing questions and answers. If you have any more questions or answers about Drupal themeing, feel free to ask here in comments, I will answer and will try to compile them in a new Drupal Themeing Q&A post.