【问题标题】:How do I write a NationBuilder partial template that displays uncached content?如何编写显示未缓存内容的 NationBuilder 部分模板?
【发布时间】:2015-10-01 05:46:04
【问题描述】:

我使用 Liquid 模板语言为 NationBuilder 编写了部分模板(据我所知,Liquid 是唯一的选择)。

<h2 class="latest"><a href="/blog">News</a></h2>
{% for post in page.blog.most_recent_blog_posts limit:3 offset:0 %}
  <div style="font-weight: bold; font-size: 16px;"><a href="{{ post.url }}">{{ post.headline }}</a></div>
  <div class="byline">
  {{ post.author.published_name_linked }} &middot; {{ post.published_at | date: '%B %d, %Y %l:%M %p' }}
  {% if post.show_stream? %}
    {% if post.public_activities_count > 0 %}
    &middot; <a href="{{ post.url }}#reactions">{{ post.public_activities_count }} reaction{% if post.public_activities_count > 1 %}s{% endif %}</a>
    {% endif %}
  {% endif %}
  </div>

  {% if post.blog_post.content.size > 0 %}
    {{ post.blog_post.content }}
    {% else %}
        <p />
  {% endif %}
    {% if post.blog_post.content_flip.size > 0 %}
    <div class="continue_reading"><a href="{{ post.url }}">Read more</a> &rarr;</div>
    {%endif %}
  <hr/>
{% endfor %}

此部分内容使用子页面标记包含在主页上。现在,当添加新的博客文章时,它不会出现在主页上,除非再次保存此部分,并且我推测模板的缓存渲染被删除。

有没有办法重写子页面标签或部分模板本身,以强制每次添加博客文章时重新呈现此模板?还是每次加载页面? NationBuilder 仪表板中是否有我缺少的设置?

【问题讨论】:

    标签: templates caching liquid


    【解决方案1】:

    您的代码看起来不错。而且我已经在几个使用部分动态更新的网站上工作过。

    我唯一的建议是确保在测试更新时在浏览器中关闭缓存。

    您也可以使用{% tag "tag_name" with "partial" %} 语法来拉取带有特定标签的帖子。但是,这需要您标记这些帖子。 Documentation for {% tag %}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-18
      • 2014-06-08
      • 2023-03-10
      • 2014-09-04
      • 1970-01-01
      • 2013-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多