简体   繁体   English

Pug 没有将一个特定的参数传递给 mixin 块

[英]Pug not passing one specific argument into mixin block

Running into quite into a weird issue where one specific argument doesn't get passed into the block part of a mixin.遇到一个很奇怪的问题,一个特定的参数没有传递到混入的块部分。

Input Pug输入哈巴狗

mixin a_ref(ref)
    if ref 
        a(ref=ref)
            block 
    else 
        block

span=name+source+aspect_ratio
br
+a_ref(ref)
    span=name+source+aspect_ratio

Expected HTML预计HTML

<span>2018 project/images/unsplash1.jpegaspect-[1/1]</span>
<br>
<a ref="xxx">
    <span>2018 project/images/unsplash1.jpegaspect-[1/1]</span>

Actual HTML实际HTML

<span>2018 project/images/unsplash1.jpegaspect-[1/1]</span>
<br>
<a ref="xxx">
    <span>undefined/images/unsplash1.jpegaspect-[1/1]</span>

I've tried renaming the "name" attribute into something else but the issue persists.我尝试将“名称”属性重命名为其他名称,但问题仍然存在。 Any help is welcome!欢迎任何帮助!

EDIT: Another thing to add: the attributes are defined as they are passed into another mixin from the actual html template编辑:要添加的另一件事:属性是在从实际的 html 模板传递到另一个 mixin 时定义的

mixin pf_img({name, source, ref, width="1/2", aspect_ratio="1/1", description, is_video=false} = {})
  span=name+source+aspect_ratio
  br
  +a_ref(ref)
    span=name+source+aspect_ratio

+pf_img({name:"2018 project", source:"/images/unsplash1.jpeg", ref:"xxx", description:"2018"})```

FIXED:固定的:

For anyone who runs into this issue, I narrowed it down to something further down in the mixin, where I redefined the "name" attribute;对于遇到这个问题的任何人,我将其缩小到 mixin 中更深的地方,在那里我重新定义了“name”属性; apparently that makes it undefined further up when putting it into a block.显然,当将其放入块中时,这会使它进一步未定义。

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

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