文档章节

The 3 Most Common Drupal Theming Questions and ...

芒果龙
 芒果龙
发布于 2011/11/02 14:20
字数 577
阅读 27
收藏 0

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.

本文转载自:http://timonweb.com/the-3-most-common-drupal-theming-questions-and-answers

芒果龙
粉丝 5
博文 105
码字总数 28366
作品 0
朝阳
部门经理
私信 提问
如果你在厦门欢迎来参加我们的Drupal交流研讨会!

您愿意来参加一个Drupal交流研讨会吗?欢迎! 时间: 2012.3.24 下午2点至5点。 地点: 爱特咖啡,地址:福建厦门思明区洪莲路20号一楼爱特咖啡 (牛庄文创园内)。 费用: 30元/位, 含咖啡、茶...

zhounana
2012/03/17
289
2
Drupal 7 主题(Theme)选择:初级,中级,高级(译文)

原文:Theming options: beginner, intermediate, advanced 一篇关于定制Drupal网站外观的主题(Theme)的好文。 注:以下Theme统称为主题,Theme,theming等字眼不再出现。 正文: 当开始一...

芒果龙
2011/10/19
1K
0
在Drupal7 当中可以使用最新的API获取URL

current_path() request_path()可以参考如下的文章: http://stackoverflow.com/questions/703426/how-to-get-the-full-url-of-a-drupal-page 下面的是老方法: 1. drupalgetpathalias(requ......

菠萝皮
2014/06/20
420
0
Using the Render API

What Is a Render Array? Many of the variables in template files are straightforward, but you’ll notice that some of the variables are printed along with a function called rende......

第三方支付接口
2013/12/26
116
0
Banshee 1.4.3 发布

媒体播放器 Banshee 已发布新的 1.4.3 版本。该版本改进了对 MTP 设备的支持,并修正了导致程序僵死的重要缺陷。 Banshee 1.4.3 的 Changelog 如下: * Common freeze triggered by column ...

红薯
2009/03/08
68
0

没有更多内容

加载失败,请刷新页面

加载更多

Ubuntu环境下安装PaddlePaddle

开篇 深度学习技术是目前非常热门的技术,笔者在闲暇之余决定学习一下这门技术,入门选择了百度开源的PaddlePaddle框架。 paddlepaddle介绍 飞桨(PaddlePaddle) 是国际领先的端到端开源深度学...

豫华商
31分钟前
2
0
LeetCode 第 287 号问题:寻找重复数,一道非常简单的数组遍历题,加上四个条件后感觉无从下手

今天分享的题目来源于 LeetCode 第 287 号问题:寻找重复数。 题目描述 给定一个包含 n + 1 个整数的数组 nums,其数字都在 1 到 n 之间(包括 1 和 n),可知至少存在一个重复的整数。假设只...

五分钟学算法
43分钟前
3
0
vuex mapActions

本文转载于:专业的前端网站➧vuex mapActions 在组件中使用 this.$store.dispatch('xxx') 分发 action,或者使用 mapActions 辅助函数将组件的 methods 映射为 store.dispatch 调用(需要先在...

前端老手
45分钟前
4
0
使用bash -x 调试信息查看lvextend -r的调用

--1.打开调试: [root@db01 storage]# set -x --2.执行命令: [root@db01 storage]# /usr/sbin/lvextend -r -L 710M /dev/shazam/storage + /usr/sbin/lvextend -r -L 710M /dev/shazam/sto......

突突突酱
53分钟前
3
0
Linux重定向及反弹shell详解

这里说Linux重定向的原因主要还是为了详细了解一下Linux中的反弹shell 目录 0x01 文件描述符 0x02 重定向 0x03 反弹shell 0x04 交互重定向 0x05 命令变形 0x01 文件描述符 Linux的文件描述符...

无心的梦呓
59分钟前
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部