0

我正在使用 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 %}

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

4

1 回答 1

2

Well, first of all you need to have an image asset of a thumb-up. Let's say you do get one and put it here: web/images/like.png

Then all you need to do is this (assuming pagination.sortable('likes', 'u.likePoints') returns the string "like"):

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

Of course, you'll probably want to put the image resource in your bundle and publish it with assets:install web, for encapsulations/organizational purposes.

EDIT

There are a lot of ways to solve what you're talking about. One would be to make a macro.

In Your\Bundle\Resources\views\Macros\bootstrap.html.twig

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

Then, in the template you need it in

{% import "YourBundle:Macros:bootstrap.html.twig" as bootstrap %}

{% set heading = pagination.sortable('likes', 'u.likePoints') %}
<th class="{{ bootstrap.icon_class(heading) }}">{{ heading }}</th>
于 2012-07-12T16:04:56.673 回答