1

I'm evaluating DocPad at the moment to see if it will be suitable for our website amongst other things. I'm having trouble working out how to use structured metadata in eco templates. I'm pretty sure it's related to How to display Backbone nested attribute using Eco? but that's unanswered too.

My page looks like:

--- 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…

and the eco template like:

---
layout: default
---

<article id="post" class="post">
    <h1><%= @document.title %></h1>
    <h2>By: <%= @document.author.email %></h2>
    <div class="post-content"><%- @content %></div>
</article>

The @document.author.email leads to the following error being logged:

TypeError: Cannot read property 'email' of undefined

How do I access that structured metadata?

thanks

4

2 回答 2

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

而且效果很好。对不起,法语的文字,但我想这对于一个例子来说并不重要。

于 2013-01-10T14:01:23.300 回答
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}')

重要的是每一行,它必须说“in 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>
于 2013-06-05T02:39:29.753 回答