theme 資料呈現的操作(view)

7 篇文章 / 0 new
最新文章
author
theme 資料呈現的操作(view)
Theme developer theme開發的輔助模組(說明)
自訂 theme 相關檔案
.info 基本定義檔及相關資料定義, 詳述 , 預設值 , d7預設
template.php 1. 用來實作相關的 hook
2. 當 template.php 內有與 模組內註冊的theme名稱相同, 則會覆載原模組註冊func 改以 template.php 內func為主
theme-setting.php 實作 theme UI介面內的參數設定內容
習慣性目錄規則 css, js, templates, color, images templates 放置自訂的 *.tpl.php, 若無自訂 tpl 則自動採用系統核心的 tpl , 覆載 tpl命名規則
系統核心模板 $variables[] 為各 tpl.php 均有的系統變數, 除 $variables['p1'] 用法外, 亦可直接以 $p1取值,($variables[] 內 key值 均可以變數型態直接取值$key)
html.tpl.php This is the default template that displays the basic HTML structure of a page on a Drupal site. The focus of this theme file is on the elements between the opening <HTML> tag and the start of the <body> tag.
可用變數如下 Variables for Use With in the html.tpl.php File
page.tpl.php The next template file we’ll examine is the page.tpl.php file. This template file focuses on the elements
that are displayed between the <body> and </body> tags and includes the HTML structure of the page,
including DIV tags and snippets of PHP code.
Standard Variables Available to page.tpl.php
region.tpl.php Standard Variables Available to region.tpl.php
node.tpl.php This template file defines how individual nodes are displayed on your site.
Standard Variables Available to node.tpl.php
block.tpl.php Standard Variables Available to block.tpl.php
field.tpl.php This template file is used for theming fields and, unlike the previous templates, isn’t automatically called by Drupal when rendering fields. If you wish to use this template, you’ll need to copy it from
/modules/fields/templates into your theme’s directory.
Standard Variables Available to field.tpl.php

主要程序
hook_theme() 內定義各組 theme的資料後, 在程式內透過  theme() 函式來調用
hook_theme($existing, $type, $theme, $path) 定義各組佈景參數, 如 themeKey, 傳數參數,template等等 system.api.php
     
hook_process_HOOK(&$variables) 不再使用, 改以 hook_preprocess_HOOK() 替代 theme.api.php
hook_preprocess_HOOK(&$variables) 可對資料源的前置處理, 第二個HOOK, 可以是html, link..一些html tag, 也可是其他模組名稱, 如node, blog, fullcalander 等等, 詳細用法需再研究  
  如 breadcrumb, 系統呼叫的順序
template_preprocess()
 ►template_preprocess_breadcrumb()
  ►anyMODULE_preprocess()
   ►anyMODULE_preprocess_breadcrumb()
    ►phptemplate_preprocess()
     ►phptemplate_preprocess_breadcrumb()
      ►anyTHEME_preprocess()
       ►anyTHEME_preprocess_breadcrumb()
        ►template_process()
 
     
theme($hook, $variables = array()) 調用定義好的 theme來呈現資料
系統已提供的 Theme Functions
theme.inc
  替換原有 theme function 行為模式,
1. 可採 程式內實作該theme function (如 MODULENAME_breadcrumb)替代原有 theme_breadcrumb(),
2. 使用 template 程式內放入自訂的 breadcrumb.tpl.php
這樣程式中呼叫 theme('breadcrumb', $variables); 就不會呼叫原系統提供的 theme function.
 
     

示意圖
模板區域 程序示意

資源
https://drupal.org/node/171194
https://drupal.org/node/190815
author
Variables for Use With in the html.tpl.php File
Variable Description of contents
$css An array of CSS files for the current page
$language (object) The language the site is being displayed in
$language->language  Contains its textual representation
$language->dir Contains the language direction; it will be either “ltr” or “rtl”.
$rdf_namespaces All the RDF namespace prefixes used in the HTML document
$grddl_profile A GRDDL profile allowing agents to extract the RDF data
$head_title A modified version of the page title, for use in the TITLE tag
$head Markup for the HEAD section(including meta tags, keyword tags, and so on)
$styles  Style tags necessary toimport all CSS files for the page
$scripts Script tags necessary to load the JavaScript files and settings for the page
$page_top  Initial markup from any modules that have altered the page; this variable should always be output first, before all other dynamic content.
$page The rendered page content; Drupal replaces$page with the content of
  page.tpl.php (see the following section).
$page_bottom  Final closing markup from any modules that have altered the page; this variable should always be output last, after all other dynamic content.
$classes String of classes that can be used to style contextually through CSS; by default the $classes variable contains the following:html front logged-in one-sidebar sidebar-first page-node toolbar toolbar-drawer, each of which can be used as suffixes to things like DIV IDs and classes.
author
Standard Variables Available to page.tpl.php
Variable Description of contents
$base_path The base URL path of the Drupal installation; at the very least, this will always default to /.
$directory The directory the template is located in, e.g.,modules/system or themes/bartik
$is_front TRUE if the current page is the front page
$logged_in TRUE if the user is registered and signed in
$is_admin TRUE if the user has permission to access administration pages
$front_page The URL of the front page; use this instead of $base_path when linking to the front page. This includes the language domain or prefix.
$logo The path to the logo image, as defined in the theme’s configuration
$site_name The name of the site, empty when it has been disabled in theme settings
$site_slogan The slogan of the site, empty when it has been disabled in theme settings
$main_menu (array) An array containing the main menu links for the site, if they have been configured
$secondary_menu (array) An array containing the secondary menu links for the site, if they have been configured
$breadcrumb The breadcrumb trail for the current page
$title_prefix An array containing additional output populated by modules, intendedto be displayed in front of the main title tag that appears in the template
$title The page title, for use in the actual HTML content
$title_suffix (array) An array containing additional output populated by modules, intendedto be displayed after the main title tag thatappears in the template
$message Status and error messages that should be displayed prominently
$tabs (array) Tabs linking to any sub-pages beneath the current page
$action_links (array) Actions local to the page, such as “Add menu” on the menu administration interface
$feed_icons A string of all the feed icons for the current page
$node The node object, if there is an automatically loaded node associated withthe page, and the node ID is the second argument in the page’s path (e.g., node/12345 and node/12345/revisions, butnot comment/reply/12345).
author
Standard Variables Available to region.tpl.php
Variable Description of contents
$content The content for this region, typically blocks
$classes A string of classes that can be used to style contextually through CSS; it can be manipulated through the variable $classesarray from preprocess functions. The default valuescan be one ormore of the followingregions. The current template type, i.e., “theming hookregion-[name]: The name of the region withunderscores replaced with dashes; for example, the page_top region would have a region-page-top class.
$region The name of the region variable as defined in the theme’s .info file
$classes Array of HTML class attribute values; it is flattened into a string within thevariable $classes.
$is_admin Flags TRUE when the current user is an administrator
$is_front Flags TRUE when presented in the front page
$logged_in Flags true when the current user is a logged-in member
author
Standard Variables Available to node.tpl.php
Variable Description of contents
$title The (sanitized) version of the title
$content (array) An array of the elements that make up the node being displayed; if you want to display the entire node, use render($content), or as explained previously with the hide() and show() functions, you can display individual elements of a node object.
$user_picture The node author’s picture from user-picture.tpl.php
$date Formatted creation date; preprocess functions can reformat it by calling format_date() with the desired parameters on the $created variable.
$name Themed username of node author output from theme_username()
$node_url Direct URL of the current node
$display_submitted A flag (TRUE or FALSE) that specifies whether submission information should be displayed
$classes String of classes that can be used to style contextually through CSS; it can be manipulated through the variable $classes_array from preprocess functions. The default values can be one or more of the following:
node: The current template type, i.e.,“theming hook”
node-[type]: The current node type. For example, if the node is a “Blog entry” itwould result in “node-blog”. Note that the machine name will often be in a shortform of the human-readable label.
node-teaser: Nodes in teaser form
node-preview: Nodes in preview mode
The following are controlled through the node publishingoptions.
node-promoted: Nodes promoted to the front page
node-sticky: Nodes ordered above other non-sticky nodes in teaser listings
node-unpublished: Unpublished nodes visible only to administrators
$title_prefix (array) An array containing additional output populated by modules, intended to be displayed in front of the main title tag thatappears in the template
$title_suffix (array) An array containing additional output populated by modules, intended to be displayed immediately after the main title tag that appears in the template
$node The full node object
$type Node type, i.e., story, page, blog, etc.
$comment_count Number of comments attached to a node
$uid The UID of the node’s author
$created Time the node was published in Unix timestamp format
$classes_array Array of HTML class attribute values; it is flattened into a string with the variable $classes.
$zebra Outputs either “even” or “odd”; useful for zebra striping in teaser listings
$id Position of the node; increments each time it’s output
$view_mode View mode, e.g., “full” or “teaser”
$page Flag for the full page state (TRUE or FALSE)
$promote Flag for front page promotion state (TRUE or FALSE)
$sticky Flags for sticky post setting
$status Flag for published status
$comment State of comment settings for the node
$readmore Flag that is set to TRUE if the teaser content of the node cannot hold the main
body content
$is_front Flag that is set to TRUE when the content is presented on the front page of the
site
$logged_in Flag that is set to TRUE when the current user is a logged-in member
$is_admin Flag that is set to TRUE when the current user is an administrator
author
Standard Variables Available to field.tpl.php
Variable Description of contents
$items An array of field values; use render() to output them.
$label The item’s label
$label_hidden A flag (TRUE or FALSE) that can be used to set whether the label should be displayed
$classes A string of classes that can be used to style contextually through CSS; itcan be manipulated through CSS. It can be manipulated through the variable $classes array from preprocess functions. The default valuescan be one ormore of the following:
field: The current template type, i.e., “theming hook”
field-name-[field_name]: The current fieldname; for example, if the fieldname is “field_description”, it would result in “field-name-field-description”.
field-type-[field_type]: The current field type; for example, if the field type is “text”, it would result in “field-type-text”.
field-label-[label_display]: The current label position; for example, if the label position is “above”, it would result in“field-label-above”.
$element['#object'] The entity that the field is attached to
$element['#view_mode'] The view mode of the entity that the field isattached to, e.g., “full” or “teaser”
$element['#field_name'] The fieldname
$element['#field_type'] The field type
$element['#field_language'] The field language
author
Standard Variables Available to block.tpl.php
Variable Description of contents
$block->subject The block title
$content The block’s content
$block->module The module that generated the block
$block->delta An ID for the block, unique within each module
$block->region The block region embedding the current block
$classes A string of classes that can be used to style contextually through CSS; it can be manipulated through the variable $classesarray from preprocess functions. The default values can be one or more of the following:block: The current template type, i.e., “theming hook”block-[module]: The module generating the block; for example, the user module is responsible for handling the default user navigation block. In thatcase, the class would be “block-user”.
$title_prefix (array) An array containing additional output populated by modules, intended to be displayed in front of the main title tag thatappears in the template
$title_suffix (array) An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template
#classes_array (array) An array of HTML class attribute values; it is flattened intoa string withinthe variable $classes.
$block_zebra Outputs “odd” and “even” dependent on each block region
$block_id Dependent on each block region
$id Same output as $block_id but independent of any block region
$is_front A flag (TRUE or FALSE) that indicates whether the current page is the homepage of the site
$logged_in A flag (TRUE or FALSE) that indicates whether the visitor is logged in
$is_admin A flag (TRUE or FALSE) that indicates whether the visitor is logged in as an admin user
$block_html_id A valid HTML ID that is guaranteed unique
 
發表回應前,請先登入
Free Web Hosting