【发布时间】:2015-05-27 10:47:31
【问题描述】:
我需要通过数据 JSON 文件创建数百个静态 产品 html 页面
首先,我将从 data.json
中加载所有产品信息然后,将其加载到product-page模板中,
最后,应用到layout模板
我怎么能在middleman中完成它
或者,如果我可以通过任何现有 gem 生成带有 product-page 的所有产品静态页面
data.json
```json
[
{
product_name: "~~"
product_images_link: "~~"
product_price: "~~"
product_description: "~~"
},
{
product_name: "~~"
product_images_link: "~~"
product_price: "~~"
product_description: "~~"
}
]
```
布局
%html
%head
%link{:href => "/stylesheets/bootstrap.css", :rel => "stylesheet", :type => "text/css"}/
%body.overview
= yield
%script{:src => "/javascripts/overview.js"}
产品页面
.head
.product_info
%h1= product_name
%h1= product_price
= product_description
.image
%img{:alt => "", :src => "#{product_images_link}"}/
【问题讨论】:
-
如果您需要从模板生成文本,您是否考虑过尝试erb?
-
嗨@floum 有没有关于erb 生成的简单教程或链接?
-
查看这个优秀的指南:stuartellis.eu/articles/erb