You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Freemarker模板需求:如何展示编号1-4与6-10的活跃频道?

Solution for Filtering Freemarker Channel List

Got it, let's tweak your code to only show channels numbered 1-4 and 6-10 while keeping all your existing rendering logic intact. Here's how to do it:

Modified Code

[#list activeChannels?sort_by("number")?filter(channel -> channel.number != 5) as channel] 
  <div class="kanal"> 
    <div class="row"> 
      <div class="column20" style="display: inline-block; vertical-align: middle;"> 
        <div><input type="checkbox" class="regular-checkbox big-checkbox" style="vertical-align: middle;" id="${channel.id}" ${channelSubscriptions?seq_contains(channel.id)?string("checked='checked'", "")}/> 
        <label for="${channel.id}"></label></div> 
      </div> 
      <div class="column80">
        <div style="width:30%; float:left;"> 
          [#if channel.imageUrl?has_content] 
            <img src=" ${channel.imageUrl} " style="width: 85%; display: inline-block; vertical-align: middle;"> 
            <!-- Bildgröße--> 
          [#else] [/#if]
        </div> 
        <div class="title" style="width:70%; float:left;">${channel.name}[#if channel.description?has_content]<br /><span style="font-style:italic; font-weight:normal;">${channel.description}</span>[/#if]</div> 
      </div> 
    </div> 
    <div style="clear: both;"></div> 
  </div> 
  [#if channel_has_next] 
    <div style="height: 20px; width: 100%;"></div> 
    <!--Abstand zwischen Kanälen--> 
  [/#if] 
[/#list]

More Robust Explicit Range Check

If you want to ensure only channels strictly within 1-4 and 6-10 are included (in case there are channels with numbers outside 1-10), use this filter instead:

[#list activeChannels?sort_by("number")?filter(channel -> (channel.number >= 1 && channel.number <=4) || (channel.number >=6 && channel.number <=10)) as channel]

What We Changed

  • We added the ?filter operator to your sorted channel list. This lets you define a condition each channel must pass to be rendered.
  • The first approach simply excludes channel number 5, which directly matches your request. The second approach explicitly checks allowed ranges, which is safer if your channel numbering might ever expand beyond 1-10.
  • All your existing UI logic (checkboxes, images, titles, spacing) remains exactly as you had it—we're just narrowing down which channels get displayed.

内容的提问来源于stack exchange,提问作者DerGaukler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:48:22