【问题标题】:Kentico - Bootstrap carousel to hide controller if there's only one itemKentico - 如果只有一个项目,则引导轮播以隐藏控制器
【发布时间】:2017-01-10 19:21:49
【问题描述】:

我正在 kentico 9 上实现 bootstrap 3 轮播,如果可能的话,如果只剩下一个项目,我需要一些帮助来自动隐藏轮播控件(包括圆形指示器和下一个/上一个箭头)。

我为轮播设置了一个新的页面类型,其中每个横幅都是 /hero/ 文件夹下内容树中的一个页面。然后使用了 2 个中继器:第一个显示圆形指示器;第二个显示横幅信息。一切运作良好。

指标中继器的设置方式如下:

Content before: <ol class="carousel-indicators">
Content after </ol>
Item transformation: <li data-target="#hero-banner" data-slide-to="<%# DataItemIndex%>" class="<%# (DataItemIndex == 0 ? "active" : "" ) %>"></li>

这意味着第一个圆圈始终存在。如何隐藏它并摆脱之前/之后内容中的&lt;ol&gt;标签?

下一个/上一个箭头再次出现在 webpart 区域内容之后,其中有这个 html:

<a class="left carousel-control" href="#hero-banner" data-slide="prev"><span class="icon-prev"></span></a>
<a class="right carousel-control" href="#hero-banner" data-slide="next"><span class="icon-next"></span></a>
</div>   <!--/#hero-banner-->

使用之前/之后的内容就像将其硬编码到页面上,但我不知道如何使其仅在我们有多个项目时动态自动显示。你能帮忙吗?

【问题讨论】:

    标签: kentico


    【解决方案1】:

    你可以使用&lt;%# DataItemCount %&gt;其中一种[变换方法][1]

    [1]: https://docs.kentico.com/display/K8/Reference+-+Transformation+methods 确定有多少项目。如果有多个,则只需添加 html。像

    <%# If(DataItemCount > 1,'html for more than one item','html for only one') %>
    

    当然,如果您使用之前/之后的信封来显示箭头,您还可以使用 jquery 来确定有多少项目并据此隐藏箭头。

    $(function(){    
      if($(".carousel-indicators li").length == 1){
           $(".left.carousel-control").hide();
           $(".right.carousel-control").hide();
        }
    });
    

    【讨论】:

    • 谢谢!我非常喜欢 Kentico,忘记了 jquery 在之前/之后显示内容方面的内容:)。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2013-12-26
    • 2020-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-03
    相关资源
    最近更新 更多