If statement 如何使用gulp文件include测试上下文变量的存在性
我正在使用If statement 如何使用gulp文件include测试上下文变量的存在性,if-statement,testing,gulp,If Statement,Testing,Gulp,我正在使用gulpfileinclude使用一些部分和模板构建我的html页面。通过使用上下文变量,我可以自定义每个meta标题。但是,我不知道只有当上下文变量存在时,才能包含一行,因为“@@else”语句似乎不存在 我的父HTML看起来像: @@include ('_header.html', { "title":"my page", "description": "description", "canonical":"http://www.sourcefromquot
gulpfileinclude
使用一些部分和模板构建我的html页面。通过使用上下文变量,我可以自定义每个meta
标题。但是,我不知道只有当上下文变量存在时,才能包含一行,因为“@@else”语句似乎不存在
我的父HTML看起来像:
@@include ('_header.html', {
"title":"my page",
"description": "description",
"canonical":"http://www.sourcefromquote.com" })
<body>
A wonderful Page
@@include ('_footer.html")
</body></html>
如果未在父HTML中设置“canonical”变量,则会抛出错误(canonical未定义
)
我想我可以在变量中包含full标记,而忽略@@if
,但这并不像预期的那样干净
有什么想法吗?
提前感谢。在标题中输入:
@@if (context.canonical) {<link rel="canonical" href="@@canonical" />}
@@include('_head.html', {
"canonical" : "https://www.website.com/canonical-link.html"
})
@@include('_head.html', {
"canonical" : "https://www.website.com/canonical-link.html"
})