2016-07-26 4 views
0

私はheader.jadeファイルをインクルードするためにdashboard.jadeにincludeタグを持っていますが、header.jadeファイルには独自のスタイルシートがあり、 jadeのスタイルシートは、含まれているheader.jadeにも適用されます。 dashboard.jadeのスタイルシートをインクルードされたheader.jadeにのみ適用する方法はありますか?現在のページと混在するタグのスタイルシートを含めたくない

ここdashboard.jadeのための私のコードです:

doctype html 
 
html 
 
    head 
 
    title Todo List 
 
    | 	 
 
    |  
 
    link(rel='stylesheet', type='text/css', href='assets/css/todos.css') 
 
    | 	 
 
    |  
 
    link(href='https://fonts.googleapis.com/css?family=Roboto:400,700,500', rel='stylesheet', type='text/css') 
 
    | 	 
 
    |  
 
    link(rel='stylesheet', type='text/css', href=' https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.css') 
 
    | 	 
 
    |  
 
    link(rel='stylesheet', href='//cdnjs.cloudflare.com/ajax/libs/lemonade/2.1.0/lemonade.min.css') 
 
    | 	 
 
    |  
 
    script(type='text/javascript', src='assets/plugins/jquery-3.0.0.min.js') 
 
    |  
 
    | 
 
    body 
 
    include partials/header

そして、ここではheader.jadeのための私のコードです:

doctype html 
 
html 
 
    head 
 
    title Eisenhower Productivity Tool 
 
    // Meta 
 
    meta(charset='utf-8') 
 
    |  
 
    meta(http-equiv='X-UA-Compatible', content='IE=edge') 
 
    |  
 
    meta(name='viewport', content='width=device-width, initial-scale=1.0') 
 
    |  
 
    meta(name='description', content='') 
 
    |  
 
    meta(name='author', content='') 
 
    |  
 
    |  
 
    link(rel='shortcut icon', href='../favicon.ico') 
 
    | 
 
    |  
 
    link(href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800', rel='stylesheet', type='text/css') 
 
    // Global CSS 
 
    link(href='../assets/plugins/bootstrap/css/bootstrap.min.css', rel='stylesheet') 
 
    // Plugins CSS 
 
    link(rel='stylesheet', href='../assets/plugins/font-awesome/css/font-awesome.css') 
 
    // Theme CSS 
 
    link#theme-style(rel='stylesheet', href='assets/css/styles.css')

A nyの助けが大変感謝しています、ありがとう!

+0

あなたはブロック文とデフォルトのテーマを拡張し、レイアウトベースの環境を使用しようとしたことがありますか?それぞれのページにvarsを使用して、状況をチェックすることができます。 – Daniel

+0

@Daniel 'extends layout'のように意味しますか?私はそれを試みたので、それは私のためにとてもうまくいくようには思われません。お時間をいただきありがとうございます! –

+0

あなたが言っているのはレイアウトを「拡張」している場合、「どのようにヴァールを使って条件をチェックしますか?私はそれが非常に無知な質問かもしれないが、それでもなお知っている。 –

答えて

0

異なるCSSスタイルシートを使用するには、一般的なJade/Pug block文でレイアウトベースの環境を使用することをおすすめします。

doctype html 

block vars 
    // Some default variables 

html 

    head 
    block head 
     // default head for title and meta 

    block defaultCSS 
     // default css 
     link(rel='stylesheet', type='text/css', href='path/to/default_style.css') 
     style. 
     body {} 

    block additionalCSS 

    body 
    block body 
     // default html in body 
    block footer 

    block defaultJS 
    script. 
     var someDefaltJavaScript = 'awsome" 

そして、ここでテンプレートファイル

template_1.jade:これはあなたのレイアウトファイルmylayout.jade可能性があり

|--./ 
|-- |--jade 
|-- |-- |-- layouts 
|-- |-- |-- |-- mylayout.jade 
|-- |-- |-- template_1.jade 
|-- |-- |-- template_2.jade 

これはlayoutbasedフォルダstructurは次のように見ることができる方法です。

extends layout/mylayout.pug 

block head 
    // this overrides the default "block head" from the layout 
    // So put your special meta for your page here 

block additionalCSS 
    link(rel='stylesheet', type='text/css', href='path/to/other_style.css') 

block body 
    .this 
    .is 
     #where 
     .your.content.goes 

template_2.jadehttp://jade-lang.com/reference/extends/

extends layout/mylayout.pug 

block head 
    // this overrides the default "block head" from the layout 
    // So put your special meta for your page here 

//- We dont use the "block additionalCSS" because we dont need it in this template 

block body 
    .this 
    .is 
     #where 
     .your.content.goes 

ここでは、唯一のtemplatefilesをコンパイルするために注意してくださいは、他のいくつかの例です。

また、githubの上の私のこの小さなヒスイのアプリに見ることができます。h ttps://github.com/pure180/gulp-pug-inheritance-test/tree/master/app

+0

ありがとうダニエル!出来た! :) –

関連する問題