As a website operator who is deeply familiar with the operation of AnQin CMS, I know well the impact of content presentation on user experience and the professionalism of the website.In daily content management, we often encounter scenarios where flexible control of content conversion is required, especially for content written in Markdown format.pageDetailTagsrenderThe parameter is the key.

The importance of controlling Markdown content conversion

The content is the soul of the website, and its presentation directly affects the reading experience of the reader.In the Anqi CMS, we tend to use Markdown to write content, as it is concise and efficient, allowing us to focus on the content itself without paying too much attention to formatting.However, when displaying Markdown content to the user, it is usually necessary to convert it to standard HTML format.The Markdown editor built into Anqi CMS will automatically handle this conversion process when enabled in the background.But sometimes, due to special requirements or specific content management strategies, we need to exercise more refined control over this automatic conversion behavior.pageDetailthe tag inrenderThe parameter is designed to meet this need.

pageDetailTags andrenderCombination of parameters

pageDetailLabels play the role of obtaining detailed information of single pages in the Security CMS.It can help us easily call the page's title, content, description, and other properties in the template.ContentWhen a field is, since it may contain Markdown syntax,renderthe parameter takes effect.

This parameter allows us to explicitly indicate whether the system shouldContentField Markdown text execution conversion. It accepts two boolean values:trueorfalse.

Whenrenderparameter settingstruethen the system will强制转换ContentThe Markdown content in the field is parsed and converted to HTML format.This means that the content will be output in HTML form regardless of whether the Markdown editor is enabled in the background.This is crucial for ensuring that all single-page content written in Markdown is presented uniformly in rich text style on the frontend.

on the contrary, if you convertrenderparameter settingsfalsethe system will not perform the conversion onContentField performs Markdown to HTML conversion. At this time,pageDetailLabels will directly output the original Markdown text.This approach is suitable for those who want to display raw Markdown code on the front end or plan to use client-side JavaScript libraries for Markdown rendering.

Syntax example in practical application:

If we want to retrieve and render Markdown content on a single page as HTML, we can do it like this:

{# 默认用法,自动获取当前页面单页,并渲染Markdown内容 #}
<div>单页内容(已渲染):{% pageDetail with name="Content" render=true %}{{pageContent|safe}}</div>

{# 获取指定单页ID的内容,并渲染Markdown内容 #}
<div>单页内容(已渲染):{% pageDetail pageContent with name="Content" id="1" render=true %}{{pageContent|safe}}</div>

Please note that when outputting the rendered HTML content, we usually use in conjunction with|safeFilter. This is to inform the template engine that this content is safe HTML and does not need to be escaped twice, thus avoiding that HTML tags are displayed as plain text.

If our requirement is to obtain the original Markdown text without any conversion, for example, to display Markdown code snippets on the page, we can set it like this:

{# 获取当前页面单页的原始Markdown内容 #}
<div>单页内容(原始Markdown):{% pageDetail with name="Content" render=false %}{{pageContent}}</div>

{# 获取指定单页ID的原始Markdown内容 #}
<div>单页内容(原始Markdown):{% pageDetail pageContent with name="Content" id="1" render=false %}{{pageContent}}</div>

In this case, since we do not expect the content to be parsed as HTML, it is usually not necessary to use|safeFilter.

Why do we need this control?

Flexible control of the conversion of Markdown content has many practical meanings.Firstly, it provides greater freedom for front-end developers.For example, we may want to use custom CSS styles to render Markdown elements on certain specific pages, rather than relying on the default HTML output style of the CMS.Now, outputting the original Markdown and rendering it on the client side is particularly convenient.

其次,for some pages that require displaying code or tutorials, we may wish to directly display the Markdown source code, so that readers can copy or refer to it. Usingrender=falseIt can easily achieve this goal.

In addition, when the Markdown editor's enabled status of the background changes,renderThe parameter provides a clear, independent rendering strategy from the background settings, ensuring that the display logic of the front-end content always meets our expectations and avoids front-end display issues caused by adjustments to the background configuration.

It is worth mentioning that in addition topageDetail标签外,English CMS中的archiveDetail(Document Details) andcategoryDetail(分类详情)标签也提供了类似的render参数,用于控制其各自ContentField Markdown conversion. This ensures consistent and controllable rendering behavior between different content types.

Summary

pageDetailTagsrenderThe parameter is a powerful and flexible tool provided by AnQi CMS in terms of content presentation.It grants website operators fine-grained control over the Markdown content conversion process, whether it is to force rendering as HTML to maintain a unified visual style, or to directly output the original Markdown to achieve specific functions, all of which can be achieved through simple parameter configuration.This design concept reflects that Anqi CMS not only provides efficient content management solutions but also fully considers the needs of diverse content presentation.


Frequently Asked Questions

如果我在pageDetailNot specified in the tag.renderParameters, how will Markdown content be displayed?

InpageDetailNot specified in the tag.renderParameters, the rendering behavior of Markdown content will depend on the global settings of the Security CMS backend.Specifically, if the Markdown editor is enabled in "Security CMS backend -> Global settings -> Content settings", the Markdown content will be automatically converted to HTML.If the Markdown editor is disabled, the content will be output in its original Markdown text form.render=trueorrender=false.

Can I display Markdown content in its original code form on the website frontend instead of converting it to HTML?

Yes, absolutely. To achieve this, you canpageDetailput in the tagrenderparameter settingsfalse, for example:{% pageDetail pageContent with name="Content" render=false %}{{pageContent}}like this,pageContentThe variable will contain the original Markdown text that has not been converted, which you can display directly on the web page or use a JavaScript library for custom rendering on the client side.

renderParameter is only applicable topageDetailIs the label valid?

No.renderParameter is a general mechanism in AnQi CMS, used to control the conversion of Markdown content. In addition topageDetailthe tag,archiveDetailLabel (used to get document details) andcategoryDetailLabel (used to get category details) ofContentfields also support usingrenderParameters control the behavior of converting Markdown to HTML. This design ensures the consistency and flexibility of rendering logic when handling different types of content.