首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用动态布局与玉石和快车

如何使用动态布局与玉石和快车
EN

Stack Overflow用户
提问于 2013-08-02 13:17:03
回答 1查看 879关注 0票数 3

我试图使用动态布局与翡翠和快车。我见过很多其他的方法,但从来没有办法干净利落的。

我的应用程序将有很多种模板,包括动态的其他模板。就像我的应用程序keystone,所以没有它我就不能走得更远.

下面是一个示例(3种模板类型):template_1 template_2 template_3

template_1包括template_2和其他template_3

所以如果它是静态的,我会这样做:

代码语言:javascript
运行
复制
# template.coffee
exports.index = (req, res) ->
  res.render 'template_1'

# template 1
Some HAML content

block content
  div.block
    include template_2
  div.block
    include template_3

但是,我想给出要通过局部变量使用的模板列表:

所以,我想做这样的事

代码语言:javascript
运行
复制
# template.coffee
exports.index = (req, res) ->
  res.render 'template_1', {
    template_list: [
      'template_2',
      'template_3'
    ]
  }

# template 1
Some HAML content

block content
  - each current_template in template_list
    div.block
      include current_template

代码语言:javascript
运行
复制
# template 1
Some HAML content

block content
  - each current_template in template
    div.block
      include #{current_template}

但不起作用。在包含扩展为字符串之后,它需要任何内容.

似乎玉石是事先编好的。

那么,是否有可能制造动态夹杂呢?或者是部分?还是动态布局?

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2015-01-12 22:36:04

考虑在客户端使用jadeify:https://github.com/domenic/jadeify,如果您也在使用browserify的话。

您可以这样做:

代码语言:javascript
运行
复制
var template = require("./template.jade");

document.getElementById("my-thing").innerHTML = template({
    localVar: "value",
    anotherOne: "another value"
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18017851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档