我正在评估DocPad,看看它是否适合我们的网站等。我在制定如何在eco模板中使用结构化元数据时遇到了麻烦。我很确定这与How to display Backbone nested attribute using Eco?有关,但也没有答案。
我的页面如下:
--- yaml
layout: 'post'
title: "Samuel Johnson's garret - an unexpected lull"
category: 'Digital Publishing'
author:
name: Author Name
page: author
email: author.name@ourdomain.co.uk
---
Unexpected free time, a chilly walk, a brown plaque leads me to
[Dr Johnson's house (http://www.drjohnsonshouse.org/) near Fleet-Street…
和eco模板如:
---
layout: default
---
<article id="post" class="post">
<h1><%= @document.title %></h1>
<h2>By: <%= @document.author.email %></h2>
<div class="post-content"><%- @content %></div>
</article>
@document.author.email
会导致记录以下错误:
TypeError: Cannot read property 'email' of undefined
如何访问结构化元数据?
感谢
答案 0 :(得分:2)
一切似乎都好。当我测试相同的结构时,行<%= @document.author.email %>
起作用。也许你使用白色空格和标签有某种不一致的地方?您可以在此网站上验证您的YAML:http://yamllint.com。
我个人也在元数据中使用对象数组:
choices:
-
text: "Mercure"
feedback: "Mercure est la planète la plus proche du Soleil, elle se situe à une distance de 0,4 UA"
value: 0
-
text: "Neptune"
feedback: "C'est effectivement la planète la plus éloignée avec une distance de 30 UA."
value: 1
它很有效。对不起法语文本,但我想这对一个例子来说并不重要。
答案 1 :(得分:0)
你可以看到这个例子,它现在完美运行,我发现了我的问题,我想与你分享解决方案:
---
slides:
-
detailimage: "heliski-img.png"
mainimage: "heliski-g.jpg"
title: "Powder South Heliski Guides"
-
detailimage: "nuevos-vientos-img.png"
mainimage: "nuevos-vientos.jpg"
title: "Centro Experiencial Nuevos Vientos"
---
#full-width-slider.royalSlider.heroSlider.rsMinW
each slide in document.slides
.rsContent
img.rsImg(src='/slideshow/#{slide.mainimage}', alt='#{slide.title}')
.infoBlock.infoBlockLeftBlack.rsABlock(data-fade-effect='', data-move-offset='10', data-move-effect='bottom', data-speed='200')
p #{slide.title}
img.rsImg(src='/slideshow/#{slide.detailimage}', alt='#{slide.title}')
重要的是每一行,它必须说“在document.slides”,所以我可以从玉器访问文档元数据。 :d
最终渲染将如下所示:
<div id="full-width-slider" class="royalSlider heroSlider rsMinW">
<div class="rsContent"><img src="/slideshow/heliski-g.jpg" alt="Powder South Heliski Guides" class="rsImg">
<div data-fade-effect="" data-move-offset="10" data-move-effect="bottom" data-speed="200" class="infoBlock infoBlockLeftBlack rsABlock"></div>
<p>Powder South Heliski Guides</p><img src="/slideshow/heliski-img.png" alt="Powder South Heliski Guides" class="rsImg">
</div>
<div class="rsContent"><img src="/slideshow/nuevos-vientos.jpg" alt="Centro Experiencial Nuevos Vientos" class="rsImg">
<div data-fade-effect="" data-move-offset="10" data-move-effect="bottom" data-speed="200" class="infoBlock infoBlockLeftBlack rsABlock"></div>
<p>Centro Experiencial Nuevos Vientos</p><img src="/slideshow/nuevos-vientos-img.png" alt="Centro Experiencial Nuevos Vientos" class="rsImg">
</div>
</div>