2

我在 StreamField 中使用 TableBlock。渲染页面,包括表格,都很好。但是无论如何允许用户在表格单元格中输入链接?只需添加一个 URL,它就会呈现为文本(正如我所期望的那样)。

这需要自定义渲染器吗?

4

2 回答 2

4

我们的内容团队也要求提供此功能。但是,它在使用的底层库中不受支持TableBlock。我们最终创建了一个自定义StreamField类型来显示链接列表,而不是尝试将链接合并到TableBlock.

于 2018-03-18T11:02:53.060 回答
0

我也遇到了这个问题。我知道这个问题很久以前就发布了,但我还是想分享我的解决方案。我放弃了,但后来我尝试像 FlipperPA 提到的那样实施降价。我意识到在安装wagtail-markdown之后(请按照说明进行操作),我可以像这样调整我的模板:

<!-- added this at the top of my template -->
{% load wagtailmarkdown %}
....
....
<!-- then in the table replace the word `linebreaksbr` with the word `markdown` -->
<table 
    class="info-list table table-responsive">
    {% if value.table.table_header %}
    <thead>
        <tr>
            {% for column in value.table.table_header %}
            {% with forloop.counter0 as col_index %}
            <th scope="col" {% cell_classname 0 col_index %}>
                {% if column.strip %}
                {% if html_renderer %}
                {{ column.strip|safe|markdown }}  <-- HERE it was {{ column.strip|safe|linebreaksbr }} -->
                {% else %}
                {{ column.strip|markdown }} <-- HERE it was {{ column.strip|linebreaksbr }} -->
                {% endif %}
                {% endif %}
            </th>
            {% endwith %}
            {% endfor %}
        </tr>
    </thead>
    {% endif %}
    <tbody>
        {% for row in value.table.data %}
        {% with forloop.counter0 as row_index %}
        <tr>
            {% for column in row %}
            {% with forloop.counter0 as col_index %}
            {% if first_col_is_header and forloop.first %}
            <th scope="row"
                {% cell_classname row_index col_index value.table.table_header %}>
                {% if column.strip %}
                {% if html_renderer %}
                {{ column.strip|safe|markdown }} <-- HERE it was {{ column.strip|safe|linebreaksbr }} -->
                {% else %}
                {{ column.strip|markdown }} <-- HERE it was {{ column.strip|linebreaksbr }} -->
                {% endif %}
                {% endif %}
            </th>
            {% else %}
            <td {% cell_classname row_index col_index value.table.table_header %}>
                {% if column.strip %}
                {% if html_renderer %} 
                {{ column.strip|safe|markdown }} <-- HERE it was {{ column.strip|safe|linebreaksbr }} -->
                {% else %}
                {% else %}
                {{ column.strip|markdown }} <-- HERE it was {{ column.strip|linebreaksbr }} -->
                {% endif %}
                {% endif %}
            </td>
            {% endif %}
            {% endwith %}
            {% endfor %}
        </tr>
        {% endwith %}
        {% endfor %}
    </tbody>
</table>

它会在 html 中呈现您的 TableBlock。我希望这对将来会有所帮助。

于 2021-05-21T14:02:00.313 回答