【问题标题】:Access single content entry in LocomotiveCMS访问 LocomotiveCMS 中的单个内容条目
【发布时间】:2016-02-04 10:54:38
【问题描述】:

我想在页面上显示单个内容条目(来自一种内容类型),并且我想通过链接直接访问此页面。

到目前为止,我已经创建了内容类型“帖子”(使用 wagon generate ...)。它包含字段“标题”、“日期”和“正文”。在“帖子”页面上,列出了帖子的所有标题,当您单击其中一个标题时,您应该被重定向到包含其余内容的子页面“帖子”(取决于您选择的帖子)。

posts.liquid:

{% extends parent %}
     {% block main %}

            {% for post in contents.posts%}
                   <a href="/{{ post._slug }}"><li>{{ post.date }} - {{ post.titel }}  </li></a>
            {% endfor %}

    {% endblock %}

这列出了所有帖子。

post.liquid:

{% extends parent %}
     {% block main %}

       <h2>{{post.title}}</h2>
       <h3>{{post.date}}</h3>
       <p>{{post.body}}</p>

      {% endblock %}

这应该是单个页面上其余内容的模板。

如何将列表元素链接到正确的帖子? 我正在使用 wagon 在本地开发网站。

【问题讨论】:

    标签: html liquid locomotivecms


    【解决方案1】:

    我找到了解决问题的方法。

    要仅访问内容类型帖子中的一个特定条目,您需要创建一个模板来保存具有正确布局的内容。

    这意味着您需要一个名为“content-type-template.liquid”的文件,并且该文件必须放在一个文件夹中(在我的例子中名为“post”)来定义父级:

    /posts.liquid                          # Holds a list of all Posts
    /post/content-type-template.liquid     # Holds the layout for only one post
    

    同样在 content-type-template.liquid 的顶部,您需要定义 content-type 和 slug:

    --- 
    title: Post Template
    content_type: post
    slug: content_type_template
    ---
    

    现在可以使用以下语法访问内容类型的字段:

    {% extends parent %}
     {% block main %}
    
       <h2>{{post.title}}</h2>
       <h3>{{post.date}}</h3>
       <p>{{post.body}}</p>
    
      {% endblock %}
    

    如果内容类型例如命名为“产品”,您需要将上面所有名为“帖子”的内容重命名为“产品”。

    最后你可以用它的蛞蝓找到一个条目。

    {% extends parent %}
     {% block main %}
    
            {% for post in contents.posts%}
                   <a href="/post/{{ post._slug }}"><li>{{ post.date }} - {{ post.titel }}  </li></a>
            {% endfor %}
    
    {% endblock %}
    

    以下是一些对我有帮助的链接:

    http://www.tommyblue.it/2011/02/28/how-to-build-a-website-with-locomotive-cms-from-scratch/

    http://doc.locomotivecms.com/references/api/objects/content-entry

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多