【问题标题】:how to render rich-text contentful如何呈现富文本内容
【发布时间】:2020-07-23 09:10:21
【问题描述】:

我尝试渲染一个内容丰富的富文本字段,它是一个有序列表。 我安装了 gem 富文本渲染器 [https://github.com/contentful/rich-text-renderer.rb] 但我不知道如何呈现富文本,有没有人有一个例子,一个教程或者可以在这一点上帮助我?

在我看来,我这样称呼这个领域:

<% tools = contentful.entries(content_type:'tools',include: 2)%>

但无法正确显示名为 test 的字段

【问题讨论】:

    标签: ruby contentful


    【解决方案1】:

    安装内容丰富的富文本渲染器

    gem 'rich_text_renderer', '~> 0.2.1'
    

    运行

    bundle install
    

    在控制器中创建渲染器

    @renderer = RichTextRenderer::Renderer.new
    

    然后在你的视图中使用它

    <% tools = contentful.entries(content_type:'tools', include: 2)%>
    <% tools.each do |tool| %>
      <div class="contentful_product">
        <h1><%= tool.title %></h1>
        <%= @renderer.render(tool.description).html_safe %>
      </div>
    <% end %>
    

    【讨论】:

      猜你喜欢
      • 2021-11-14
      • 1970-01-01
      • 2022-01-22
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多