问题描述
在 jade
中创建一个我希望 stylus
过滤器使用的变量.
使用 #{var}
似乎不起作用.例如,这段代码:
给出结果错误:
/home/data/tnt/server/node/www/tech/cool.jade:21|div2|背景色粉红色> 3|颜色 #{color1}4|预期缩进",得到缩进"如何让 jade
变量 color1
在 stylus
过滤器中可见?
过滤器(如手写笔、markdown 等)在编译时"期间执行,并且仅执行一次.
但是文本替换是在运行时完成的,因此过滤器无法访问变量.
过滤器只能访问原始文本,例如.color #{color1}
而不是 color blue
作为一种解决方法,您可以创建一个辅助方法,您可以按照在多个地方的建议进行手写笔模板化和渲染(我只找到了使用 Markdown 过滤器的示例,但过滤器的工作方式相同,因此它们也适用于 过滤器):
creating a variable within jade
that I wish the stylus
filter to use.
using #{var}
does not appear to work. for example, this code:
- var color1 = 'blue' stylus: div background-color pink color #{color1}
gives resulting error:
/home/data/tnt/server/node/www/tech/cool.jade:2 1| div 2| background-color pink > 3| color #{color1} 4| expected "indent", got "outdent"
how do I get the jade
variable color1
visible within the stylus
filter?
Filters (like stylus, markdown etc.) are executed during "compile-time", and only once.
But text replacement is done during run-time, so filters don't have access to variables.
Filters can only access the raw text eg. color #{color1}
and not color blue
As a workaround you can create a helper method where you do stylus templating and rendering yourself as suggested in multiple places (I've only found examples which are used the markdown filter but filters are working the same so they apply also the stylus
filter):
- Jade: Pass markdown filter a variable.
- :markdown filter processing the text of a String variable
- :markdown with variable
这篇关于在 node.js 中,如何将变量从 jade 传递给 :stylus 过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!