在自定义主题中输出结果时,有三个部分或更多特殊的函数,如 hook_menu,Page Callback,MODULE_theme 钩子

1、hook_menu

为了使用自定义的实体,像创建、编辑、删除、查看实体的功能,就必须要创建一些 Menu path,这里创建、编辑、删除是与Drupal's Form API相关的,通过hook_menu,可以定义我们需要的路径来访问这个新创建的实体内容

function my_module_menu() {$items['my_entity/%my_entity'] = array('title callback'   => 'my_entity_page_title','title arguments'  => array(1),'page callback'    => 'my_entity_page_view','page arguments'   => array(1),'access arguments' => array('view entities'),'type'             => MENU_CALLBACK,);return $items;}

2、Page Callback

在上面的例子中,我们在访问这个路径时,定义了 page callback 对应的 my_entity_page_view 函数,因此,接下来就需要创建这个函数,如下

/*** This is the callback we defined to be executed when a user* requests http://mysite.com/my_entity/1 (1 is just an example ID,* it could be anything). This function will set up the data and* prepare the render array(s). You will specify the template to* use in this callback. The critical thing to note below is the* order in which field_attach_prepare_view, entity_prepare_view* and field_attach_view are called. These functions must be called* in this order and they must be called before you specify which* theme to use.*/function my_entity_page_view($entity, $view_mode='full') {$entity_type = $entity->entityType();$entity_id = entity_id($entity_type, $entity);//// Remove previously built content, if exists//$entity->content = array();$entity->title = filter_xss($entity->title);//// Build the fields content//field_attach_prepare_view($entity_type, array($entity_id => $entity), $view_mode);entity_prepare_view($entity_type, array($entity_id => $entity));$entity->content += field_attach_view($entity_type, $entity, $view_mode);// Specify the theme to use and set the #element. Note that the key// you use to pass the entity object must match the key you set in the// variables in my_module_theme(). So in the case below, we use the key// named #element because in my_module_theme() we set the following code://// array(//   'my_entity' => array(//     'variables' => array('element' => null),//     'template' => 'my_entity'//   ),// );//$entity->content += array('#theme'     => $entity_type,'#element'   => $entity,'#view_mode' => $view_mode,'#language'  => LANGUAGE_NONE,);return $entity->content;}

3、MODULE_theme() Hook

到目前为止,为了这个实体我们已经定义了菜单项还有CALL BACK返回值,接下来,剩下的就需要创建一个指向模板的文件,看上面部分内容,可以看到内容为:

$entity->content += array('#theme' => 'my_entity');

意思是说,指向 my_entity ,那么,应该如何定义呢?

function my_module_theme($existing, $type, $theme, $path) {return array('my_entity' => array('variables' => array('element' => null),'template' => 'my_entity_template'),);}

4、根据第三部分的内容,我们则需要创建名为 my_entity_template.tpl.php 的模板文件

[php// In a real module variables should be manipulated in a preprocess function.$content = $element->content;]
<div class="[php print $classes; ]">
[php print render($content['title']); ]
[php print render($content['field_date']); ][php print render($content['field_author']);][php print render($content['field_image']);]
[php print render($content['field_description']);]

原文链接:https://drupal.org/node/1238606

Drupal 自定义主题实体 Theming Custom Entities相关推荐

  1. Drupal 自己定义主题实体 Theming Custom Entities

    在自己定义主题中输出结果时,有三个部分或很多其它特殊的函数.如 hook_menu,Page Callback.MODULE_theme 钩子 1.hook_menu 为了使用自己定义的实体.像创建. ...

  2. 如何在Angular Material中制作自定义主题

    by Charlee Li 通过李李 如何在Angular Material中制作自定义主题 (How to make a custom theme in Angular Material) Angu ...

  3. VS Code 安装插件、自定义模板、自定义配置参数、自定义主题、配置参数说明、常用的扩展插件

    1. 下载和官网教程 下载地址:https://code.visualstudio.com/ 官方教程:https://code.visualstudio.com/docs 2. 安装插件 安装扩展插 ...

  4. ExtJS4.2:自定义主题 入门

    背景 用过 ExtJs 的朋友都有一种趋势:审美疲劳,好在 Ext4.1 之后的版本提供了快速自定义主题的功能,本文的内容主要来自:http://docs.sencha.com/extjs/4.2.2 ...

  5. Drupal 7 主题模板概述

    Drupal是一个开源的内容管理系统(CMS) 平台,它是用PHP写成的.主要用于构造提供多种功能和服务的动态网站,这些功能包括用户管理(UserAdministration).发布工作流 (Publ ...

  6. Dev-cpp自定义主题:

    Dev-cpp自定义主题 1.在安装目录...\config\下新建文本文件,重命名为CustomTheme.syntax: 2.打开CustomTheme.syntax,复制以下内容并保存: [Ed ...

  7. Drupal 6 主题制作指南

    译者:老葛, http://www.thinkindrupal.com/theme-guide-drupal-6 原文:http://drupal.org/theme-guide 欢迎来到主题制作的用 ...

  8. 彰显个性│博客园的自定义主题

    目录预览 一.开放的博客园 二.主题推荐 三.自定义主题配置CSS 四.自定义主题配置JS 五.页面加载loading 六.页面看板 七.动态背景 八.标签动效 一.开放的博客园 在国内,开源社区有很 ...

  9. zsh安装与自定义主题

    zsh安装与自定义主题 ​   Zsh(Z-shell)是一款用于交互式使用的shell,也可以作为脚本解释器来使用.其包含了 bash, ksh,tcsh 等其他shell中许多优秀功能,也拥有诸多 ...

最新文章

  1. struts2 标签中read-only=true 和disabled的区别
  2. labview生成HTML报表,LabVIEW201
  3. 皮尔逊相关系数的计算(python代码版)
  4. R语言:预测算法常用包总结
  5. Bit-Z 关于交易隐藏及下线说明
  6. Codeforces Round #547 (Div. 3)
  7. python中的tkinter_基于python中tkinter的计算机实现
  8. linux 主机的网络属性基本配置:
  9. java json传值到前台_json前后台传值
  10. crop video in ffmpeg
  11. FMEA失效模式和影响分析
  12. 【番外篇】波动率的几种模型
  13. spring-AOP 增强接口Introductions
  14. Windows超级管理器 8.72 这一刻,刻不容缓。
  15. 华东理工大学pk华东师范大学计算机专业,华东理工大学朱为宏教授和华东师范大学杨海波教授合作在光控手性金属配位自组装体系的研究中取得突破性进展...
  16. 爬虫07 爬取阿里旅行特价机票
  17. 为什么有人会说「感谢拼多多」,让一贫如洗的我还能活下去?
  18. apk多开制作方法 试用ApkEditor 1.8 旗舰版轻松制作apk多开双开
  19. 未解决:自行打包cpio格式的Ramdisk,与编译成功生成的kernel.bin,deviceTree一起打包成image.ub,不能正常启动kernel的问题???
  20. 试衣网的商业模式很脆弱

热门文章

  1. 各自然带代表植被_必备知识:植被与地理环境
  2. 云服务器系统盘升级会不会丢失数据,云服务器 系统盘快还是数据盘快
  3. php框架中什么是渲染,thinkPHP5框架渲染模板的3种方式简述
  4. 推荐的Oracle书籍
  5. linux看是否连上服务器
  6. Spring常见面试题
  7. c语言样本,C语言样本教案 第二章
  8. ugui unity 取消选择_关于Unity中的UGUI优化,你可能遇到这些问题
  9. 攻防演练中的业务逻辑漏洞及检测思路
  10. 基础练习 查找整数 c语言