As a veteran with many years of experience in website operation, I am well aware that how to efficiently obtain and utilize content data in a content management system is crucial for improving user experience and website maintenance efficiency.Auto CMS (AutoCMS) provides many intuitive template tags with its simple and efficient features, making content operation more flexible.prevArchiveLabel to get the previous documentIdfield.
How to cleverly get the previous document in AnQi CMSIdfields?
When building website content, especially for blogs, news, or product detail pages, we often need to provide users with 'Previous' and 'Next' navigation links to guide them through continuous reading and optimize the internal flow. Anqi CMS provides special template tags for this.prevArchiveLabel is used to retrieve the information of the “previous” document of the current document.
KnowprevArchivetags
prevArchiveThe design philosophy of the label is to simplify operations as much as possible, it can automatically recognize the context of the current page without any parameters, and try to obtain documents sorted before the current document.After successfully obtaining the previous document, it will fill all related data of the document into a variable you specify, making it convenient for you to call in the template.
For example, you can enable it in the template in the following way.prevArchiveTags:
{% prevArchive prev %}
{# 在这里,您就可以使用 'prev' 变量来访问上一篇文档的数据了 #}
{% endprevArchive %}
In this code,prevIt is the variable name specified for the data in the previous document. Once the tag executes successfully,prevthe variable will become an object containing various properties of the previous document.
to get the previous document'sIdField
SinceprevArchiveLabel has placed all available data from the previous document inprevthe variable, so getting theIdfield becomes extremely simple. You just need to use the.dot operator to directly access itprevVariablesIdproperty.
IdIs the unique identifier for each document in the Safe CMS system, usually an integer.It is very useful for building dynamic links, performing backend data interaction, or handling specific logic in frontend JS.
The following is a complete example of obtaining and using the previous document in a real template:IdA complete example of the field:
{% prevArchive prev %}
{% if prev %}
<div class="prev-document-navigation">
<p>上一篇:
<a href="{{ prev.Link }}" title="{{ prev.Title }}">
{{ prev.Title }}
<small>(文档ID: {{ prev.Id }})</small>
</a>
</p>
</div>
{% else %}
<div class="prev-document-navigation">
<p>上一篇:没有了</p>
</div>
{% endif %}
{% endprevArchive %}
Let's parse this code step by step:
{% prevArchive prev %}: This line of code indicates that the security CMS is to find the previous content of the current document and assign the found data to a variable namedprev.{% if prev %}: This is a very important judgment. It checksprevDoes the variable really have a value. If the current document is the first in the series, there will be no previous document,prevThe variable will be empty. This judgment can avoid trying to access a non-existent field when there is no previous document, which may cause a page error.<a href="{{ prev.Link }}" ...>: Ifprev存在,we can safely access its properties.{{ prev.Link }}It will output the URL link of the previous document.{{ prev.Title }}It will output the title of the document.<small>(文档ID: {{ prev.Id }})</small>: This is exactly what we are looking for!{{ prev.Id }}It will directly output the previous document'sIdfield value. You can decide whether to display it on the front end according to your actual needsId, or use it behind the scenes for other logical processing.{% else %}: IfprevThe variable is empty, which means there is no previous document, and we then display a prompt like “No more” to ensure the completeness of the user experience.{% endif %}and{% endprevArchive %}: They are conditional judgment andprevArchiveThe end tag of the label, ensuring the correctness of the template syntax structure.
By using the above method, you can not only easily get to the previous document,Idbut also simultaneously getTitle/LinkOther commonly used fields are added to build a beautifully designed and functional navigation page.The template tag system of AnQi CMS is just like that, through the intuitive variable call, converting complex backend data processing into a simple and easy-to-understand frontend display.
Common Questions (FAQ)
Q1:prevArchiveTag can obtain the current document'sId?A1: No.prevArchiveThe design purpose of the label is to obtain information from the "Previous" document, it only returns the data of the document immediately preceding the current document in the sorting sequence. To obtain the information of the current document,Id,You should directly use it in the detail page template{{ archive.Id }}(Assuming the current document variable name is)archive) or{% archiveDetail with name="Id" %}Such tags.
Q2: If my website has multiple content models or categories,prevArchivehow will the "previous article" tag be determined?A2:prevArchiveTags are usually searched for in the current document. This means that if you are currently browsing an article under the "Article Model" category of the "Technical Sharing" category,The same content model and categorythe previous document will be searched for.prevArchiveIt will search for the previous article adjacent to the "Article Model" document list in the "Technical Sharing" category. This ensures the continuity and relevance of navigation.
Q3: BesidesId,prevArchiveWhat are some commonly used document fields that tags can retrieve?A3:prevArchivethe tags you getprevThe variable contains many useful fields from the previous document, in addition toIdYou can also directly access{{ prev.Title }}(Document Title)、{{ prev.Link }}(Document Link)、{{ prev.Description }}(Document description),{{ prev.CategoryId }}(Category ID),{{ prev.Views }}(Views)、{{ prev.Logo }}(cover first image),{{ prev.Thumb }}(Cover thumbnail) and{{ prev.CreatedTime }}(Creation time) and others. These fields are sufficient to meet the needs of most navigation and information display.