Drupal8系列(五):主題製作之搭建框架-Ubuntu 14.04 LTS

Drupal8的主題製作準備工作已經完成了,那麼我們接下來就開始正式製作主題了!


一、生成主題的Compass框架

首先我們先進入到Druapl8的主題目錄:

cd /var/www/druapl8/themes

然後利用Compass生成主題框架:

compass create firehare --css-dir=css --images-dir=img --javascripts-dir=js -r bootstrap-sass --using bootstrap

在上述命令中firehare是要生成的主題目錄,--*-dir表示指定的目錄名,如--css-dir=css就表示編譯生成的css目錄叫css,--images-dir=img則表示圖像目錄是img等,-r bootstrap-sass表示該主題框架要求bootstrap-sass項目,並使用bootstrap框架。

輸入上述命令,將會出現以下的信息:

directory firehare/ 
directory firehare/css/ 
directory firehare/fonts/bootstrap/ 
directory firehare/js/ 
directory firehare/js/bootstrap/ 
directory firehare/sass/ 
   create firehare/config.rb 
   create firehare/sass/styles.scss 
   create firehare/sass/_bootstrap-variables.scss 
... ...
To import your new stylesheets add the following lines of HTML (or equivalent) to your webpage:
<head>
  <link href="/css/styles.css" rel="stylesheet" type="text/css" />
</head>

 上述信息的出現,表示主題框架基本生成。


二、讓Drupal知道主題

與Drupal7不同的是,在Drupal8中使用.info.yml來代替.info文件,在這裏,需要創建firehare.info.yml文件,其內容如下所示:

name: firehare
type: theme
description: An extremely flexible, responsive theme with a wealth of regions based on bootstrap. 
version: 1.0-alpha
core: 8.x
engine: twig

stylesheets:
  all:
    - css/style.css
    
regions:
    pre_header_first: 'Pre Header First'
    pre_header_second: 'Pre Header Second'
    pre_header_third: 'Pre Header Third'
    pre_header: 'Pre Header'
    header_top_left: 'Header Top Left'
    header_top_right: 'Header Top Right'
    header: Header
    navigation: 'Navigation'
    banner: 'Banner'
    highlighted: Highlighted
    promoted: 'Promoted'
    content: Content
    sidebar_first: 'Sidebar First'
    sidebar_second: 'Sidebar Second'
    bottom_content: 'Bottom Content'
    footer_first: 'Footer First'
    footer_second: 'Footer Second'
    footer_third: 'Footer Third'
    footer_fourth: 'Footer Fourth'
    footer: Footer
    help: Help
    page_top: 'Page top'
    page_bottom: 'Page bottom'

在生成該文件之後,進入Druapl8的管理》外觀界面,你將會找到一個名爲firehare且沒有screenshot的主題,表示Drupal8已經知道有這麼一個主題存在了。


三、添加所需的CSS和JS

這是Drupal8與Drupal7差異比較大的地方,Drupal8是依賴.libraries.yml文件來啓用相關的Javascript的,所創建的firehare.libraries.yml文件內容如下:

base:
  version: 1.0-alpha
  css:
    theme:
      css/style.css: {}
      
bootstrap_javascript:
  version: 3.2.0.1
  js:
    js/bootstrap.js: {}
  dependencies:
    - core/jquery
    - core/jquery.once
    - core/drupal

大家不難看到在libraries文件和info文件中都有對css文件的定義,而且是重複的,關於這一點我查了一下Drupal8自帶的bartik主題,也是在兩個文件中進行重複定義的,所以就先讓它這麼重複着,等以後看到官方正式說明後再做修改好了,這一段先存疑待考吧!


綜上所述,主題的基本框架就已經搭建起來了,接下來就是對主題進行細化了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章