如何通过 Locomotive CMS RESTful API 访问 content_type 条目?我只能找到有限的文档。
我设法使用以下方法获取了我的身份验证令牌:
curl -v -H 'Content-Type: Application/json' -d '{"email":"your@email.abc", "password":"foo"}' 'https://your.locomotive.instance.tld/locomotive/api/v3/tokens.json'
但现在我想访问我的 content_entries 并在页面上显示他们的数据。
背景
我正在 Locomotive CMS 中构建一个自定义导航片段,我希望 content_type 条目与页面一起列在导航中。
具体来说(显然)我只希望在 content_type 设置了 content_type_template 时列出条目。
我最初认为我可以简单地遍历我的页面,使用 slug 找到任何页面content_type_template
,抓住该页面的句柄并将其设置为变量,然后使用该变量获取如下条目:
{% for loopPage in page.children %}
{% assign myContentType = '' %}
{% if page.slug == 'content_type_template' %}
{% assign myContentType = loopPage.handle %}
{% for item in contents.myContentType %}
<li>a href="{{ item._slug }}">{{ item.name }}</a></li>
{% endfor %}
{% else %}
<li><a href="{% path_to loopPage %}">{{ loopPage.title }}</a></li>
{% endif %}
{% endfor %}
但这不起作用。根据我的 StackOverflow Q & A here,似乎不可能以这种方式使用 Liquid 变量。
因此需要通过其他方法访问 content_type 条目,例如 Locomotive CMS REST API。