The 3 Most Common Drupal Theming Questions and ...

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.

Here are the most common Drupal Theming Questions:

  1. How to output comments anywhere within a Drupal theme?
  2. How to get rid of (remove) ‘Search this site’ label from a search box
  3. How to output a view anywhere within a Drupal theme?

1. How to output comments anywhere within a Drupal theme?

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:

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.

2. How to get rid of (remove) ‘Search this site’ label from a search box

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:

a) To remove label from theme’s main search form (which is called by $search_box):

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:

$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):

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:

$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.

3) How to output a view anywhere within a Drupal theme?

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.

转载于:https://my.oschina.net/u/187928/blog/34366

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值