weixin_39563132
weixin_39563132
2021-01-12 15:36

Variables inside block tags

This code:


h3.subtitle
  | Title text

Compiles to:

 html
<h3 class="subtitle">
  Title text
</h3>

So the text inside is always placed on a new line.

There's an issue on variables usage, here's an example:


h3.subtitle
  - if $lang == 'de'
    | Title text, de
  - else
    | Title text, en

HTML output:

 html
<h3 class="subtitle">Title text, de
</h3>

There's no new line, text is placed directly after the opening tag. Same happens for the inline tags:


h3.subtitle
  - if $lang == 'de'
    a href='#" Title text, de
  - else
    a href='#" Title text, en

HTML output:

 html
<h3 class="subtitle"><a href="#">Title text, de</a>
</h3>

I hope this issue can be fixed.

该提问来源于开源项目:slim-template/slim

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

7条回答

  • weixin_39974557 weixin_39974557 3月前

    I cannot reproduce this. Which version do you use?

    点赞 评论 复制链接分享
  • weixin_39563132 weixin_39563132 3月前

    Slim v2.0.1.

    Here's an example http://d.pr/f/1LHG

    点赞 评论 复制链接分享
  • weixin_39974557 weixin_39974557 3月前

    Please post your examples as a gist or something similar. I don't want to download a zip

    点赞 评论 复制链接分享
  • weixin_39563132 weixin_39563132 3月前

    http://snippi.com/s/txcushr

    点赞 评论 复制链接分享
  • weixin_39974557 weixin_39974557 3月前

    Thanks for reporting this. Unfortunately there seems to be no easy fix for this in Temple::HTML::Pretty. Since it affects only the indentation I don't consider it high priority.

    点赞 评论 复制链接分享
  • weixin_39615257 weixin_39615257 3月前

    For cases such as this, as a 'workaround' of sorts, one might acheive desired results using the ternerary operator in lieu of traditional if/else syntax. For instance, given the following Slim code:

     slim
    header.header
      .header_address
        h1 = $lang == 'de' ? 'Chemnitz' : 'New York'
      /! /.header_address
    

    The following HTML will be produced (using Slim 2.0.3):

     html
    <header class="header">
      <div class="header_address">
        <h1>
          New York
        </h1>
      </div>
      <!--/.header_address-->
    </header>
    
    点赞 评论 复制链接分享
  • weixin_39716703 weixin_39716703 3月前

    Just pushed test for this issue to confirm this issue is resolved

    点赞 评论 复制链接分享