用于博客标签的业务催化剂液体标记
business catalyst liquid markup for blog tags
我正在使用 blogposts 资源输出我的 blogposts 并添加分页以一次呈现三个帖子。这是按预期工作的。但是我还添加了 blogposts 资源 fields="tag" subresource="tags
所以我可以呈现与每个 blogpost 关联的标签。
但是我无法输出这部分。这是我用过的代码:
{% if globals.get.limit %}
{% assign limit = globals.get.limit | convert: "number" %}
{% else %}
{% assign limit = 3 %}
{% endif %}
{% if globals.get.skip %}
{% assign skip = globals.get.skip | convert: "number" %}
{% else %}
{% assign skip = 0 %}
{% endif %}
{% assign resource = "blogposts" fields="tag" subresource="tags"%}
{module_data resource="{{resource}}" version="v3" template="" limit="{{limit}}" skip="{{skip}}" collection="bpost"}
{% assign moduloCheck = bpost.totalItemsCount | modulo :limit %}
{% if moduloCheck == 0 %}
{% assign totalPages = bpost.totalItemsCount | divided_by: limit | minus: 1 %}
{% else %}
{% assign totalPages = bpost.totalItemsCount | divided_by: limit %}
{% endif %}
{% assign currentPage = globals.get.skip|divided_by:limit %}
<hr />
{% for item in bpost.items %}
<h2>{{item.postTitle}}</h2>
<p>{{item.postBody}}</p>
<p>Skapad <span>{{item.releaseDate | date: "yyyy-MM-dd \ hh:mm:ss tt"}}</span></p>
<p><a href="{{item.postUrl}}">Kommentera</a></p>
<br />
<ul>
{% for item in bpost.items -%}
<li><a href="/retreivepostsbytag.html?tagid={{item.tag.id}}"># {{item.tag.tagName}}</a></li>
{% endfor -%}
</ul>
<hr />
{% endfor %}
<span>Sida:
{% for pageNum in (0..totalPages) %}
{% if pageNum == currentPage %}
{{ pageNum | plus: 1 }}
{% else %}
<a href="{{ globals.get.id }}?skip={{ pageNum|times:globals.get.limit }}&limit={{ limit }}">{{ pageNum | plus: 1 }}</a>
{% endif %}
{% endfor %}
</span>
这是我尝试在其上实施此代码的测试页:testpage
谢谢,
-索海尔
标签数据的子资源请求需要为每个 post 发生一次,如下所示:
{% for item in bpost.items %}
...
{module_data resource="blogposts" version="v3" fields="objectId,tagId,objectType,siteId,tag,post" subresource="tags" resourceId="{{ item.id }}" skip="0" limit="10" order="objectType" collection="postTagData"}
<ul>
{% for tagMeta in postTagData.items -%}
<li>
<a href="/retreivepostsbytag.html?tagid={{ tagMeta.tag.id }}"
>{{ tagMeta.tag.tagName }}</a>
</li>
{% endfor -%}
</ul>
...
{% endfor %}
此外,您的 resource
变量仅被设置为 blogposts
,另一部分 (fields="tag" subresource="tags"
) 被丢弃。为了清楚起见,我将其更改为:
{% assign resource = "blogposts" %}
编辑:这是您的代码,经过修改以包含更改:
{% if globals.get.limit %}
{% assign limit = globals.get.limit | convert: "number" %}
{% else %}
{% assign limit = 3 %}
{% endif %}
{% if globals.get.skip %}
{% assign skip = globals.get.skip | convert: "number" %}
{% else %}
{% assign skip = 0 %}
{% endif %}
{% assign resource = "blogposts" %} <!-- `fields="tag" subresource="tags"` was being discarded -->
{module_data resource="{{resource}}" version="v3" template="" limit="{{limit}}" skip="{{skip}}" collection="bpost"}
{% assign moduloCheck = bpost.totalItemsCount | modulo :limit %}
{% if moduloCheck == 0 %}
{% assign totalPages = bpost.totalItemsCount | divided_by: limit | minus: 1 %}
{% else %}
{% assign totalPages = bpost.totalItemsCount | divided_by: limit %}
{% endif %}
{% assign currentPage = globals.get.skip|divided_by:limit %}
<hr />
{% for item in bpost.items %}
<h2>{{item.postTitle}}</h2>
<p>{{item.postBody}}</p>
<p>Skapad <span>{{item.releaseDate | date: "yyyy-MM-dd \ hh:mm:ss tt"}}</span></p>
<p><a href="{{item.postUrl}}">Kommentera</a></p>
<br />
{module_data resource="blogposts" version="v3" fields="objectId,tagId,objectType,siteId,tag,post" subresource="tags" resourceId="{{ item.id }}" skip="0" limit="10" order="objectType" collection="postTagData"}
<ul>
{% for tagMeta in postTagData.items -%}
<li>
<a href="/retreivepostsbytag.html?tagid={{ tagMeta.tag.id }}"
>{{ tagMeta.tag.tagName }}</a>
</li>
{% endfor -%}
</ul>
<hr />
{% endfor %}
<span>Sida:
{% for pageNum in (0..totalPages) %}
{% if pageNum == currentPage %}
{{ pageNum | plus: 1 }}
{% else %}
<a href="{{ globals.get.id }}?skip={{ pageNum|times:globals.get.limit }}&limit={{ limit }}">{{ pageNum | plus: 1 }}</a>
{% endif %}
{% endfor %}
</span>
我正在使用 blogposts 资源输出我的 blogposts 并添加分页以一次呈现三个帖子。这是按预期工作的。但是我还添加了 blogposts 资源 fields="tag" subresource="tags
所以我可以呈现与每个 blogpost 关联的标签。
但是我无法输出这部分。这是我用过的代码:
{% if globals.get.limit %}
{% assign limit = globals.get.limit | convert: "number" %}
{% else %}
{% assign limit = 3 %}
{% endif %}
{% if globals.get.skip %}
{% assign skip = globals.get.skip | convert: "number" %}
{% else %}
{% assign skip = 0 %}
{% endif %}
{% assign resource = "blogposts" fields="tag" subresource="tags"%}
{module_data resource="{{resource}}" version="v3" template="" limit="{{limit}}" skip="{{skip}}" collection="bpost"}
{% assign moduloCheck = bpost.totalItemsCount | modulo :limit %}
{% if moduloCheck == 0 %}
{% assign totalPages = bpost.totalItemsCount | divided_by: limit | minus: 1 %}
{% else %}
{% assign totalPages = bpost.totalItemsCount | divided_by: limit %}
{% endif %}
{% assign currentPage = globals.get.skip|divided_by:limit %}
<hr />
{% for item in bpost.items %}
<h2>{{item.postTitle}}</h2>
<p>{{item.postBody}}</p>
<p>Skapad <span>{{item.releaseDate | date: "yyyy-MM-dd \ hh:mm:ss tt"}}</span></p>
<p><a href="{{item.postUrl}}">Kommentera</a></p>
<br />
<ul>
{% for item in bpost.items -%}
<li><a href="/retreivepostsbytag.html?tagid={{item.tag.id}}"># {{item.tag.tagName}}</a></li>
{% endfor -%}
</ul>
<hr />
{% endfor %}
<span>Sida:
{% for pageNum in (0..totalPages) %}
{% if pageNum == currentPage %}
{{ pageNum | plus: 1 }}
{% else %}
<a href="{{ globals.get.id }}?skip={{ pageNum|times:globals.get.limit }}&limit={{ limit }}">{{ pageNum | plus: 1 }}</a>
{% endif %}
{% endfor %}
</span>
这是我尝试在其上实施此代码的测试页:testpage
谢谢, -索海尔
标签数据的子资源请求需要为每个 post 发生一次,如下所示:
{% for item in bpost.items %}
...
{module_data resource="blogposts" version="v3" fields="objectId,tagId,objectType,siteId,tag,post" subresource="tags" resourceId="{{ item.id }}" skip="0" limit="10" order="objectType" collection="postTagData"}
<ul>
{% for tagMeta in postTagData.items -%}
<li>
<a href="/retreivepostsbytag.html?tagid={{ tagMeta.tag.id }}"
>{{ tagMeta.tag.tagName }}</a>
</li>
{% endfor -%}
</ul>
...
{% endfor %}
此外,您的 resource
变量仅被设置为 blogposts
,另一部分 (fields="tag" subresource="tags"
) 被丢弃。为了清楚起见,我将其更改为:
{% assign resource = "blogposts" %}
编辑:这是您的代码,经过修改以包含更改:
{% if globals.get.limit %}
{% assign limit = globals.get.limit | convert: "number" %}
{% else %}
{% assign limit = 3 %}
{% endif %}
{% if globals.get.skip %}
{% assign skip = globals.get.skip | convert: "number" %}
{% else %}
{% assign skip = 0 %}
{% endif %}
{% assign resource = "blogposts" %} <!-- `fields="tag" subresource="tags"` was being discarded -->
{module_data resource="{{resource}}" version="v3" template="" limit="{{limit}}" skip="{{skip}}" collection="bpost"}
{% assign moduloCheck = bpost.totalItemsCount | modulo :limit %}
{% if moduloCheck == 0 %}
{% assign totalPages = bpost.totalItemsCount | divided_by: limit | minus: 1 %}
{% else %}
{% assign totalPages = bpost.totalItemsCount | divided_by: limit %}
{% endif %}
{% assign currentPage = globals.get.skip|divided_by:limit %}
<hr />
{% for item in bpost.items %}
<h2>{{item.postTitle}}</h2>
<p>{{item.postBody}}</p>
<p>Skapad <span>{{item.releaseDate | date: "yyyy-MM-dd \ hh:mm:ss tt"}}</span></p>
<p><a href="{{item.postUrl}}">Kommentera</a></p>
<br />
{module_data resource="blogposts" version="v3" fields="objectId,tagId,objectType,siteId,tag,post" subresource="tags" resourceId="{{ item.id }}" skip="0" limit="10" order="objectType" collection="postTagData"}
<ul>
{% for tagMeta in postTagData.items -%}
<li>
<a href="/retreivepostsbytag.html?tagid={{ tagMeta.tag.id }}"
>{{ tagMeta.tag.tagName }}</a>
</li>
{% endfor -%}
</ul>
<hr />
{% endfor %}
<span>Sida:
{% for pageNum in (0..totalPages) %}
{% if pageNum == currentPage %}
{{ pageNum | plus: 1 }}
{% else %}
<a href="{{ globals.get.id }}?skip={{ pageNum|times:globals.get.limit }}&limit={{ limit }}">{{ pageNum | plus: 1 }}</a>
{% endif %}
{% endfor %}
</span>