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

wagtail Internal links not working for snippets with richtextfieldgetting<a id="1" linkt

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744788874a4593791.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信