Theming Drupal 8美化Drupal8

Theming Drupal 8美化Drupal8


Last updated February 16, 2016. Created on February 2, 2013.

Edited bychris_hall_hu_cheng,guitarbound2015,HongPong,sqndr.Log in to edit this page.

翻译By我

This guide is about creating themes for Drupal 8.

这篇翻译是关于Drupal8滴。

Quite significantchanges were introduced in the theme system between Drupal 8 and 7. This guide contains information that applies to Drupal 8 and refers sometimes to Drupal 7 in order to explain new concepts and approaches.

Drupal7到8的升级是非常重大的升级,特别是theme系统的升级。这篇文字主要是说明Drupal8的不过有时也会讲些D7以示区分。

Outside drupal.org other theming guides can be found, such assqndr's excellent Drupal 8 theming guide.

有很多第三方的非常好的文章, 比如sqndr's excellent Drupal 8 theming guide这个咯, 有时间也会翻译下。

PHPTemplate has been discontinued for theming in Drupal 8; theTwig markup language is used instead. This will make Drupal 8 themes much more secure because PHP calls will no longer exist in theme files. This will also make theming easier to understand for non-programmers, front end developers and programmers coming from other languages and frameworks.

PHP模块在D8中不再使用了, 取而代之的是Twig模版, 当然了, 因为D8是drupal内核+syphomny啦。拿twig取代了PHP模版肯定是增强了安全性的,当然了也使得这个theming变的更容易被非码农,前端开发人员和码农们接受。

以下这些是关于theme的文章合集, 有空慢慢研究收货将是蛮大的。

又来那句话了, 想看打赏啊。 O(∩_∩)O~

For a collection of useful materials for themers, seeTheming and Front End Development with Drupal.

Defining a theme with an .info.yml file

Theme folder structure

Twig in Drupal 8

Adding Regions to a Theme

Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 theme

Classy themes css selectors

Creating a Drupal 8 sub-theme

Including Default Image Styles With Your Theme

Including Part Template

Using attributes in templates

Working with breakpoints in Drupal 8

Theming differences between Drupal 6, 7 & 8

Advanced Theming


好吧, 你不打赏, 我也继续翻了。没事翻着玩。呵呵

从第一篇开始吧

Defining a theme with an .info.yml file

用一个.info.yml文件定义一个主题

Last updated February 20, 2016. Created on October 3, 2014.

Edited byjp.stacey,hansfn,kay_v,lucasr.Log in to edit this page.

To create a Drupal 8 theme you need to first create a THEMENAME.info.yml file that provides meta-data about your theme to Drupal. This is similar to how modules and installation profiles are being defined, and as such it is important to set the 'type' key in the .info.yml file to 'theme' in order to differentiate it.

想做一个D8的主题, 首先要定义一个THEMENAME.info.yml的文件,它为Drupal系统提供了主题的元数据。

This page provides an example THEMENAME.info.yml file, and an overview of the information that the file can contain.

这篇文章将介绍给你这个文件的整体信息和这个文件所包含的内容。

Create an .info.yml file

You create the .info.yml file in the root of yourtheme folder. The folder should have the same name as the .info.yml file. So if your theme is named "Fluffiness" then the folder is named "fluffiness/" and the .info.yml file is named "fluffiness/fluffiness.info.yml". If the file is present your theme will be visible in your website at Manage > Appearance (http://example.com/admin/appearance).

在你主题的根目录, 创建一个文件, 目录的名字必须和主题名字一致。如果你的主题叫做Fluffiness,那文件夹的名字也是fluffiness,而且.info.yml的名字也要写成 fluffiness/fluffiness.info.yml。这个时候就可以在你的管理界面的外观管理的界面就可以看到你新建主题的名字了。

Replace spaces in the theme name with underscores in the folder name (and .info.yml file name).

Tabs areNOTallowed, use spacesONLY.

YouMUSTindent your properties and lists with 1 or more spaces.

Example举例:

name:Fluffiness

type:theme

description:A cuddly theme that offers extra fluffiness.

core:8.x

libraries:

  - fluffiness/global-styling

stylesheets-remove:

  - '@classy/css/components/tabs.css'

  - core/assets/vendor/normalize-css/normalize.css

regions:

  header:Header  

  content:Content    # the content region is required

  sidebar_first:'Sidebar first'

  footer:Footer

In your Drupal website you can find more examples of .info.yml files by looking at the themes provided by core. Open for example the folder core/themes/stark and look for the file stark.info.yml.

D8的站点里 有很多的info。yml的文件, 打开一个看看把

Keys

The following keys provide meta-data about your theme, and define some of the basic functionality.

name:Fluffiness

Required. The human readable name will appear on the Appearance page, where you can activate your theme.

description:An extra cuddly Drupal theme available in greyandblue.

Required. The description is also displayed on the Appearance page.

type:theme

Required. The type key indicates the type of extension, e.g. module, theme or profile. For themes this should always be set to "theme".

base theme:...

Recommended. The theme can inherit the resources from another theme bydefining it as a base theme. It isrecommendedto inherit from classy or stable, to ensure your own theme is more stable to any potential future changes in core theming.

core:8.x

Required. The core key specifies the version of Drupal core that your theme is compatible with.

version:8.x-1.0

For modules hosted on drupal.org, the version number will be filled in by the packaging script. You should not specify it manually, but leave out the version line entirely.

screenshot:fluffiness.png

With the screenshot key you define a screenshot that is shown on the Appearance page. If you do not define this key then Drupal will look for a file named 'screenshot.png' in the theme folder to display.

libraries:-fluffiness/global-styling

Thelibrarieskey can be used to add asset libraries — which can contain both CSS and JS assets — to all pages where the theme is active. You canread more about themes and asset libraries.

If that library was defined as follows:

global-styling:version:1.x  css:theme:css/style.css:{}css/print.css:{media:print}

Then together, that would result in this addition to the HTML:

stylesheets-remove:-core/assets/vendor/normalize-css/normalize.css# 1-'@classy/css/components/tabs.css'# 2

Note:

-#1: In most caseslibraries-overrideshould be used with a key offalseinstead of stylesheets-remove which is deprecated and will be removed in Drupal 9.

-#2: Thestylesheets-removekey removes a link to a stylesheet added by another theme or module. The full path to CSS file should be provided (instead of just the filename), to accommodate cases where more than one file with the same name exists.

-#3: In cases where a Drupal core asset is being removed (for example, a CSS file in jQuery UI) the full file path is needed. In cases where the file is part of a library that belongs to a module or theme, a token can be used. Note that when using the token it needs to be quoted because @ is a reserved indicator in YAML.

regions:header:Header  content:Content# required!sidebar_first:'Sidebar first'footer:Footer

Regions are declared as children of the regions key. Note that region keys are not preceded by a dash. You canread more about adding regions to a theme.

You arerequiredto have acontentregion.

More information

Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 theme

A full description of all the keys that are available in a *.info.yml files can be found in:Let Drupal 8 know about your module with an .info.yml file

Change record:.info files are now .info.yml files

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,198评论 4 359
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,663评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,985评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,673评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,994评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,399评论 1 211
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,717评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,407评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,112评论 1 239
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,371评论 2 241
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,891评论 1 256
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,255评论 2 250
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,881评论 3 233
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,010评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,764评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,412评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,299评论 2 260

推荐阅读更多精彩内容