在TableBlock单元格中添加链接

时间:2018-03-09 20:31:52

标签: wagtail wagtail-streamfield

我在StreamField中使用TableBlock。渲染页面,包括表格,很好。但无论如何,是否允许用户输入表格单元格的链接?简单地添加一个URL就会将其呈现为文本(正如我所料)。

这是否需要自定义渲染器?

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分: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。我希望这会对未来有所帮助。

相关问题