最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wagtail 6.3 Internal links added to a snippet not browsable - Stack Overflow

programmeradmin0浏览0评论

wagtail Internal links not working for snippets with richtextfield

getting

<a id="1" linktype="page">My Page</a>.

The snippet template has {{ value.content|richtext }}

The snippet is added to our ArticlePage model by

    ('content_module', SnippetChooserBlock(ContentModule, template='domestic/blocks/article_snippet.html')),

our article_snippet.html is

{% load wagtailcore_tags %}

<div class="block-text">
    {% if not value.hide_title %}
        <h2{% if value.title_id %} id="{{value.title_id}}"{% endif %}>{{ value.title }} </h2>
    {% endif %}
    <div>{{ value.content|richtext }}</div>
</div>

our snippet is defined as

@register_snippet
class ContentModule(ClusterableModel):
    title = models.CharField(max_length=255)
    title_id = models.CharField(
        max_length=255,
        null=True,
        blank=True,
        verbose_name=_('Title ID?'),
        help_text=(
            'Your provided ID might change upon saving to ensure its valid. '
            'Check this snippet after saving to see the formatted ID.'
        ),
    )
    content = RichTextField()
    hide_title = models.BooleanField(
        default=False,
        verbose_name=_('Hide title?'),
        help_text=('Check this box to prevent the title displaying on the page.'),
    )
    tags = TaggableManager(through=ContentModuleTag, blank=True)

    panels = [
        FieldPanel('title'),
        FieldPanel('hide_title'),
        FieldPanel('title_id'),
        FieldPanel('content'),
        FieldPanel('tags'),
    ]

wagtail Internal links not working for snippets with richtextfield

getting

<a id="1" linktype="page">My Page</a>.

The snippet template has {{ value.content|richtext }}

The snippet is added to our ArticlePage model by

    ('content_module', SnippetChooserBlock(ContentModule, template='domestic/blocks/article_snippet.html')),

our article_snippet.html is

{% load wagtailcore_tags %}

<div class="block-text">
    {% if not value.hide_title %}
        <h2{% if value.title_id %} id="{{value.title_id}}"{% endif %}>{{ value.title }} </h2>
    {% endif %}
    <div>{{ value.content|richtext }}</div>
</div>

our snippet is defined as

@register_snippet
class ContentModule(ClusterableModel):
    title = models.CharField(max_length=255)
    title_id = models.CharField(
        max_length=255,
        null=True,
        blank=True,
        verbose_name=_('Title ID?'),
        help_text=(
            'Your provided ID might change upon saving to ensure its valid. '
            'Check this snippet after saving to see the formatted ID.'
        ),
    )
    content = RichTextField()
    hide_title = models.BooleanField(
        default=False,
        verbose_name=_('Hide title?'),
        help_text=('Check this box to prevent the title displaying on the page.'),
    )
    tags = TaggableManager(through=ContentModuleTag, blank=True)

    panels = [
        FieldPanel('title'),
        FieldPanel('hide_title'),
        FieldPanel('title_id'),
        FieldPanel('content'),
        FieldPanel('tags'),
    ]
Share Improve this question edited Mar 11 at 14:45 DavidU asked Mar 11 at 14:18 DavidUDavidU 1258 bronze badges 4
  • We'll need to see more than one line of code to be able to debug this. Where is the snippet template being called from? How is value being defined? – gasman Commented Mar 11 at 14:39
  • @gasman is this a wagtail bug ? – DavidU Commented Mar 12 at 9:25
  • Have tried placing this code into a fresh Wagtail 6.3.3 project (the only thing I left out was the tags field), and links in the snippet's rich text field are rendering correctly for me. Can you confirm that the article_snippet.html template is definitely being picked up and used (by adding some dummy text to it and verifying that it shows in the output)? Also, how are you including the StreamField in your ArticlePage template - something like {{ page.content }}, or {% include_block %}, or something else? – gasman Commented Mar 12 at 12:06
  • After more investigation this is the offending code I think (thanks for the dummy text suggestion @register.filter def convert_anchor_identifiers_to_span(value): # Issue only occurs in content_modules where render_a method in core/rich_text.py does not fire, so return as-is if value.block_type != 'content_module': return value rich_text_html = value.value.content return convert_anchor_identifier_a_to_span(rich_text_html) How can I apply the richtext filter to this ? – DavidU Commented Mar 12 at 14:39
Add a comment  | 

1 Answer 1

Reset to default 0

I was looking at the wrong template it was our custon filter that did not use the richtext filter - resolved now

发布评论

评论列表(0)

  1. 暂无评论