【问题标题】:Symfony2, KnpPagination Bundle:Sorting using iconsSymfony, Knp Paginator Bundle:使用图标排序
【发布时间】:2012-07-12 15:27:13
【问题描述】:

我正在使用 KNPPanginator Bundle,对它非常满意。

但我不知道如何用图标而不是文本替换顶部的分拣机。这是我的树枝代码:

    {% block pagination_head %}
    <thead>
    <tr>

        <th>{{ pagination.sortable('likes', 'u.likePoints')|raw }}</th>
        <th>{{ pagination.sortable('title', 'u.title')|raw }}</th>
        <th>{{ pagination.sortable('date', 'u.created')|raw }}</th>



    </tr>
    </thead>
    {% endblock %}

那么我需要做什么来获得一个重击图标,而不是“喜欢”这个词? 我尝试在那里粘贴&lt;img src...&gt;,但没有帮助。

【问题讨论】:

    标签: symfony twig knppaginator


    【解决方案1】:

    嗯,首先你需要有一个竖起大拇指的图片资源。假设您确实得到了一个并将其放在这里:web/images/like.png

    那么你需要做的就是这个(假设pagination.sortable('likes', 'u.likePoints')返回字符串“like”):

    <th>{{ asset( "images/" ~ pagination.sortable('likes', 'u.likePoints') ~ ".png" }}</th>
    

    当然,出于封装/组织目的,您可能希望将图像资源放入您的包中并使用assets:install web 发布它。

    编辑

    有很多方法可以解决您所说的问题。一种是创建macro

    在 Your\Bundle\Resources\views\Macros\bootstrap.html.twig 中

    {% macro icon_class( type ) %}
      {% set type_class_map = {
        like: 'icon-user'
      } %}
      {{ type_class_map[type] }}
    {% endmacro %}
    

    然后,在你需要的模板中

    {% import "YourBundle:Macros:bootstrap.html.twig" as bootstrap %}
    
    {% set heading = pagination.sortable('likes', 'u.likePoints') %}
    <th class="{{ bootstrap.icon_class(heading) }}">{{ heading }}</th>
    

    【讨论】:

    猜你喜欢
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    • 2015-10-25
    • 2017-01-10
    • 1970-01-01
    相关资源
    最近更新 更多