jade:if 语句和嵌套 [英] jade: if statements and nesting

查看:46
本文介绍了jade:if 语句和嵌套的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑这个伪服务器端代码

if(isFixed) {<div class="fixed">} 别的 {<div>}<p>内部元素</p>

我尝试用玉来做这件事,但是...

 - if(mode === 'fixed') {div#标签栏- }p ...我不能让它成为一个内部元素:(

它总是像这样呈现,</div> 关闭:

<div id="tabbar"></div><p>我想要这个在div里面</p>

我弄乱了缩进吗?谢谢!

解决方案

您需要将控制流与模板分开.试试这个:

divClass = null如果是固定的divClass = "固定"div(类=div类)p 内部元素

这反过来可能会建议将isFixed"参数分解为要传递的实际 divClass 参数.但这当然取决于您剩余的代码/模板.

<小时>

作为替代,尝试混合:

mixin 内容p 内部元素如果(是固定的)div(类=测试")混合内容别的div(类=其他")混合内容

Concider this pseudo-ish server side code

if(isFixed) {
  <div class="fixed">
} else {
  <div>
}
    <p>Inner element</p>
  </div>

I try to do this in jade but...

 - if(mode === 'fixed') {
   div#tabbar
 - }
     p ...I cannot get this to be an inner element :(

It always renders like this, with the </div> closed:

<div id="tabbar"></div><p>I want this inside of the div</p>

Am I messing up the indention? Thanks!

解决方案

You need to separate control flow from the template. Try this:

divClass = null

if isFixed
   divClass = "fixed"

div(class=divClass)
   p inner element

Which in turn might suggest factoring out the "isFixed" parameter into the actual divClass parameter to be passed on. But that depends on your remaining code/template of course.


As an alternative, try a mixin:

mixin content
  p inner element

if (isFixed)
  div(class="test")
    mixin content
else
  div(class="other")
    mixin content

这篇关于jade:if 语句和嵌套的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆