【问题标题】:Jekyll - Include multiple parameters in single include?Jekyll - 在单个包含中包含多个参数?
【发布时间】:2020-08-14 22:29:46
【问题描述】:

是否可以在单个包含中包含多个参数?

单身:

{% include card.html class=include.class1 %}

多个??

{% include card.html class=include.class1 && include.class2 %}

还是我必须做 class1=include.class1 class2=include.class2?

【问题讨论】:

    标签: jekyll


    【解决方案1】:

    可以传递多个include参数,用空格param1=value1 param2=value2隔开,例如:

    {% include image.html url="http://jekyllrb.com"
    max-width="200px" file="logo.png" alt="Jekyll logo"
    caption="This is the Jekyll logo." %} 
    

    然后你可以访问它们前缀为include.的包含文件,例如:

    {{include.file}} {{include.caption}}
    

    【讨论】:

    • 嗨,马克!谢谢。是的,我的工作正常,更重要的是我想将多个值传递给一个参数。例如{% include card.html class=include.class1 && include.class2 %}
    • @Rhys 这样您就可以创建一个数组或将这些参数连接到一个字符串中,然后将它们作为单个值传递,然后在包含中解构它,我不明白您为什么需要这个
    • 不用担心,谢谢。我想要的唯一情况是将多个类传递给一个组件。例如,修饰符和禁用类。
    • 再次感谢您的帮助,能够使用捕获来实现这一目标。 @marcanuy
    • @Rhys 不错!很高兴它有帮助!
    【解决方案2】:

    正如@marcanuy 所说,

    一种方法是使用捕获函数将多个值包含到单个参数中。

    {% 捕获类 %} {{include.class1}} {{include.class2}} {% endcapture %}

    {% include card.html class=classes %}

    【讨论】:

      【解决方案3】:

      这是我的用例-

      一个包含 html 的单选按钮集,如下所示:

      <label>{{include.label}}</label> 
      {% for option in include.options %}
      <input type="radio" name="{{include.label}}" id="{{include.option}}" value="{{include.option}}" checked="checked"/><label for="  {{include.option}}">{{include.option}}</label>
      {% endfor %}
      

      你这样称呼:

      {% include radiobuttons.html label="favorite color" options="green", "blue", "orange", "red" %}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-03-15
        • 1970-01-01
        • 1970-01-01
        • 2019-07-27
        • 2011-08-29
        • 2020-05-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多