我如何获取正在执行的 jade 脚本的文件名 [英] How do I get the filename of the executing jade script
问题描述
是否有一个全局对象可以从带有各种参数的 jade 模板中访问?
Is there a global object that is accessible from within a jade template with various parameters?
当前执行的玉文件路径有没有全局变量?
Is there a global variable with the path of the currently executing jade file?
!!! 5
html
head
title Test
body
//- I want to be able to know what the current script file is...
p Hello, I am: #{globals.scriptfilename}
推荐答案
如果您正在使用 gulp-jade
,请将 gulp-data
添加到组合中并使用它代码:
If you're using gulp-jade
, add gulp-data
to the mix and use this code:
var jade = require('gulp-jade');
var data = require('gulp-data');
gulp.src('**/*.jade')
.pipe(data(function (file) {
return {
relativePath: file.history[0].replace(file.base, '')
};
}))
.pipe(jade())
这将在您的 jade
模板中为您提供一个 relativePath
,它类似于 about/index.jade
,相对于基本文件夹.
This will give you a relativePath
in your jade
templates that is something like about/index.jade
, relative to the base folder.
我不完全确定 file.history
在哪里/如何生成,但在我的情况下 [0]
指向原始文件名(其绝对磁盘上的路径)
I'm not entirely sure of where/how that file.history
is generated, but in my case [0]
pointed to the original filename (with its absolute path on the disk)
这篇关于我如何获取正在执行的 jade 脚本的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!