分配帕格混合蛋白到可变

发布于 2025-02-02 12:08:26 字数 388 浏览 3 评论 0原文

有什么办法将哈巴狗混合蛋白分配给变量? (nb 不是混合蛋白的结果。)

即类似的东西:

mixin a
    ...

mixin b
    ...

mixin c
    ...

-
    let myMixin;
    switch (someCondition) {
        case 1: myMixin = b; break;
        case 2: myMixin = c; break;
        default: myMixin = a;
    }

...And then use it like this further down in the template:
   +myMixin
    
    

Is there any way assigning a Pug mixin to a variable? (N.b. not the results of the mixin.)

I.e. something like this:

mixin a
    ...

mixin b
    ...

mixin c
    ...

-
    let myMixin;
    switch (someCondition) {
        case 1: myMixin = b; break;
        case 2: myMixin = c; break;
        default: myMixin = a;
    }

...And then use it like this further down in the template:
   +myMixin
    
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撑一把青伞 2025-02-09 12:08:26

您可以在哈巴狗中使用动态混合素:

+#{mixinName}()

创建一种生成动态混合物的混合蛋白,例如:

mixin dynMixin(name)
  +#{name}()

然后使用Dynamic Mixin Easy:

mixin a
  p AAA

mixin b
  p BBB

mixin c
  p CCC

-
  let myMixin;
  let someCondition = 2;
  switch (someCondition) {
    case 1: myMixin = 'b'; break;
    case 2: myMixin = 'c'; break;
    default: myMixin = 'a';
  }

+dynMixin(myMixin)
//- or write directly: +#{myMixin}()

注意: Dynamic Mixin的名称必须是字符串。

You can use dynamic mixins in Pug:

+#{mixinName}()

Create a mixin which generate a dynamic mixin, e.g.:

mixin dynMixin(name)
  +#{name}()

Then use dynamic mixin easy:

mixin a
  p AAA

mixin b
  p BBB

mixin c
  p CCC

-
  let myMixin;
  let someCondition = 2;
  switch (someCondition) {
    case 1: myMixin = 'b'; break;
    case 2: myMixin = 'c'; break;
    default: myMixin = 'a';
  }

+dynMixin(myMixin)
//- or write directly: +#{myMixin}()

Note: The name of dynamic mixin must be a string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文