简体   繁体   English

我如何编译多个玉文件

[英]how do i compile multiple jade files

let's start off with the following 4 jade files. 让我们从以下4个玉文件开始。

layout.jade layout.jade

html
    head
        block cms_head
    body
        block cms_body 

home_page.jade home_page.jade

extends layout
block append cms_head
    title home page
block append cms_body
    p superman ate so many different apples 

plugin_a.jade plugin_a.jade

block append cms_body
    p i got plugged in... genius

plugin_for_jquery.jade plugin_for_jquery.jade

block append cms_head
    script(src="/jquery-1.8.3.js")

so i can easily render the home page by doing: 这样我就可以通过执行以下操作轻松呈现主页:

app.get("/", function(req, res){
    res.render("home_page");
});

which is fantastic, however in order to allow for plugability in my app, i would like to allow their views to take advantage of existing templates, and append/prepend/replace content to whatever the plugin needs to show. 太棒了,但是为了允许在我的应用程序中实现可插入性,我希望允许他们的视图利用现有模板,并在需要显示的插件上附加/添加/替换内容。

what i am trying to do is render home_page.jade, then render plugin_a.jade and plugin_for_jquery.jade ... the basic idea is there can be a variable number of plugins, and each plugin adding it's own content to the view. 我想做的是渲染home_page.jade,然后渲染plugin_a.jade和plugin_for_jquery.jade ...基本思想是可以有可变数量的插件,每个插件都将自己的内容添加到视图中。

I tried this (obviously it didn't work) 我尝试了这个(显然没有用)

for plugin in plugins
    include= plugin.name

So any ideas on how i can do that? 那么关于我该怎么做的任何想法?

as far as i know there is no possability in jade to readout the directory 据我所知,玉石不可能读出目录

but using node: 但是使用节点:

var fs = require("fs");   

app.get("/", function(req, res){
    fs.readdir(DIR_OF_PLUGINS, function(err, list){
        res.render("home_page", {"list": list});
    });
});

and in homepage.jade 和在homepage.jade中

- for(plugin in list)
   include = plugin


btw: you should build a router and a functions document with something like 顺便说一句:您应该使用以下内容构建路由器和功能文档:

//router.js // or app.js
var funct = require("routes/functions")
app.get('/', funct.home);

//functions.js
exports.home = function(req, res){

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM