2016-05-10 3 views
0

私が理解しないこと:特定のキーワードはDocPadの@documentのように予約されているように見えますが、この言葉でカスタムデータ値を使用できますか?基本的なDocPad:変数と最初のエラー

私は

<%= data.hostimagesurl %> 

を使用していますが、私は使用しても

<%= page.hostimagesurl %> 

<%= site.hostimagesurl %> 

を見てきました、私はこれらを作ることができますか?私が使用しなければならない価値がありますか?

私は落とし穴をどこで見つけることができないのですか?ハイフンとアンダースコアは許可されていますか?

私はこれがハンドルバーのように機能していると想像しています。私は値を入力してタグを定義しています。これは正しい考えですか?

私のDocPadレイアウトが機能しない理由も混乱します。

--- 
title: "Welcome!" 
layout: "default" 
isPage: true 

hostimagesurl: "http://www.googel.com/" 

--- 

<p>Testing 1</p> 

何に:

background-image:url(<%= data.hostimagesurl %>bg.gif); 

<body style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0;min-width:100%; color:#353535; background-color:#f9f9f9; background-image:url(<%= data.hostimagesurl %>bg.gif); background-repeat: repeat; background-position:center top; font-family: Helvetica, sans-serif; font-size:13px; margin: 0; padding: 0;" yahoo="fix" bgcolor="#f9f9f9"> 

はindex.htmlファイルをレンダリングマイ次のようになります。私はちょうど私が見ることができる最初のエラーは、この行で発生

error: Something went wrong while rendering: /Users/***/my-new-website/src/render/index.html 
The error follows: 

ReferenceError: document is not defined 
    at Object.eval (<anonymous>:55:29) 
    at Object.eval (<anonymous>:67:8) 
    at eval (<anonymous>:69:6) 
    at Function.eco.render (/Users/***/my-new-website/node_modules/eco/lib/index.js:26:25) 
    at EcoPlugin.render (/Users/***/my-new-website/node_modules/docpad-plugin-eco/out/eco.plugin.js:23:32) 
    at ambi (/Users/***/my-new-website/node_modules/event-emitter-grouped/node_modules/ambi/out/lib/ambi.js:57:27) 
    at Task.<anonymous> (/Users/***/my-new-website/node_modules/event-emitter-grouped/out/lib/event-emitter-grouped.js:45:23) 
    at ambi (/Users/***/my-new-website/node_modules/ambi/es5/lib/ambi.js:98:14) 
    at Domain.fireMethod (/Users/***/my-new-website/node_modules/taskgroup/out/lib/taskgroup.js:397:23) 
    at Domain.run (domain.js:228:14) 
    at Task.fire (/Users/***/my-new-website/node_modules/taskgroup/out/lib/taskgroup.js:435:27) 
    at Immediate._onImmediate (/Users/***/my-new-website/node_modules/taskgroup/out/lib/taskgroup.js:452:26) 
    at processImmediate [as _immediateCallback] (timers.js:383:17) 

がエラーを取得しています地球私は間違っている?

+0

hostimagesurlがサイト全体の場合、templateData下にdocpad.coffeeスクリプトでそれを定義します:hostimagesurl:このような一般的なもの "http://www.googel.com/" と使う<% - @ hostimagesurl%>あなたのhtmlファイルにあります。レンダリングフォルダ内のindex.htmlファイルとそのファイルをレンダリングするためにindex.html.ecoという名前ですか? – user3257693

答えて

0
@document 

http://docpad.org/docs/beginを参照してdocpadConfig

私はまだ勉強を検索し、あなたの​​ファイルで定義することができるだけのCoffeeScript(エコ)

this.document 

変数siteのための特別な構文ですpage.whateverコードについては教えてもらえませんが、forループコードで変数の名前が付けられているループ内でよく使用されます。あなたの例では

0

あなたは現在のドキュメントを参照するとき@シンボルを忘れるの古典DocPadエラーを作りました:@documentが定義されていますが、documentではありません。 hostimagesurlあなたにアクセスするために同様に

は、2つのオブジェクトがDocPadテンプレート/ページ/レイアウトに渡され、デフォルトで@document.hostimagesurl

を呼び出す必要があります。 docpad.coffeeファイルと現在のドキュメントオブジェクトで定義されているtemplateDataプロパティ。これらのオブジェクトは、テンプレートthisコンテキストのプロパティです。 templateDataの場合、それぞれのプロパティはthisコンテキストのメンバーですが、ドキュメント自体はthisのプロパティです。

CoffeeScriptとCoffeeScriptベースのテンプレートシステムでは、this@シンボルで表されます。

これは、ECOテンプレート内で現在のドキュメントに@documentでアクセスすることを意味します。 templateDataの一部としてdocpad.coffeeファイルで定義されている@site.urlまたは@getPreparedTitle()にアクセスすることもできます。

ドキュメントのメタデータセクション(---の間)で定義されているプロパティは、ドキュメントオブジェクトのプロパティとして使用できます。

コレクションをループするときに、多くの場合、人々はpageのような変数を作成します。これらのローカル変数は、thisコンテキストを必要としません。

<%pages = @getCollection('pages').toJSON()%> 
<ul> 
    <%for page in pages:%> 
     <li> 
      <a href="<%-page.hostimagesurl%>"><%-page.title%></a> 
     </li> 
    <%end%> 
</ul> 
関連する問題