As a website operator who deeply understands the operation of Anqing CMS, I am well aware of the impact of content presentation on user experience and website professionalism.In daily content management, we often encounter scenarios where we need to flexibly control content conversion, especially for content written in Markdown format.A security CMS provides fine-grained control, among whichpageDetaillabel'srenderThe 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 reader's reading experience.In 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 users, it is usually necessary to convert it to standard HTML format.The AnQi CMS built-in Markdown editor 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 detailed control over this automatic conversion behavior.pageDetailin the labelrenderThe parameter is designed to meet this need.
pageDetailwith the tag andrenderThe combination of parameters
pageDetailThe tag plays a role in obtaining detailed information of a single page in AnQi CMS.It can help us easily call the title, content, description, and other properties of the page in the template.When we get a single page ofContentWhen a field is, because it may contain Markdown syntax,renderthe parameter takes effect.
This parameter allows us to explicitly indicate whether the system should beContentThe Markdown text in the field performs a conversion operation. It accepts two boolean values:trueorfalse.
Whenrenderthe parameter totrueWhen this is the case, the system will force a conversion to:ContentField Markdown content is parsed and converted to HTML format.This means that regardless of whether the Markdown editor is enabled in the background, the content will be output in HTML format.This is crucial to ensure that all single-page content written in Markdown is presented uniformly with rich text formatting on the front end.
On the contrary, if you changerenderthe parameter tofalsethe system will not convertContentField performs Markdown to HTML conversion. At this point,pageDetailThe label 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 a client-side JavaScript library for Markdown rendering.
Syntax example in practical application:
If we want to retrieve and render the Markdown content of a single page as HTML, we can use it in this way:
{# 默认用法,自动获取当前页面单页,并渲染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 we usually cooperate when outputting the rendered HTML content|safeFilter. This is to inform the template engine that the content is safe HTML, which does not require further escaping, thus preventing HTML tags from being 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 a webpage, 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 significances.Firstly, it provides greater freedom for front-end developers.For example, we might want to use custom CSS styles to render Markdown elements on certain specific pages instead of relying on the CMS default HTML output style.At this time, outputting the original Markdown and rendering it on the client side is particularly convenient.
Secondly, for some pages that need to display code or tutorials, we may want to directly display the Markdown source code so that readers can copy or refer to it. Usingrender=falseThis target can be easily achieved.
In addition, when the enable status of the Markdown editor in the background changes,renderA parameter provides a clear rendering strategy independent of the backend settings, ensuring that the display logic of the front-end content always meets our expectations and avoids front-end display issues caused by backend configuration adjustments.
It is worth mentioning that besidespageDetailtags, the Anqi CMS alsoarchiveDetail(Document details) andcategoryDetail(Category Details) tags alsorenderprovide similar parameters to control their respectiveContentField Markdown conversion. This ensures consistent and controllable rendering behavior between different content types.
Summary
pageDetaillabel'srenderThe parameter is a powerful and flexible tool provided by AnQi CMS in terms of content presentation.It gives website operators fine-grained control over the Markdown content conversion process, whether it is to forcibly render it as HTML to maintain a unified visual style or directly output the original Markdown to achieve specific functions, all of which can be realized through simple parameter configuration.This design concept reflects Anqi CMS's provision of efficient content management solutions while also fully considering the needs of diversified content presentation.
Frequently Asked Questions
If I am inpageDetailNot specified in the tag.renderHow will the Markdown content be displayed?
InpageDetailNot specified in the tag.renderWhen the parameter is set, the rendering behavior of Markdown content will depend on the global settings of the Anqi CMS backend.In particular, if the Markdown editor is enabled in "AnQi 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 form.Therefore, to ensure the consistency of content display, it is recommended to specify explicitlyrender=trueorrender=false.
Can I display the Markdown content as raw code on the website front end instead of converting it to HTML?
Yes, absolutely. To achieve this goal, you canpageDetailput in the tag.renderthe parameter tofalseFor example:{% pageDetail pageContent with name="Content" render=false %}{{pageContent}}Thus,pageContentThe variable will contain the original Markdown text, which you can display directly on the web page or use a JavaScript library to customize the rendering on the client side.
renderWhether the parameter is onlypageDetailThe label is valid?
Not.renderThe parameter is a general mechanism in Anqi CMS, used to control the conversion of Markdown content. In addition topageDetailthe tags,archiveDetailLabel (Used to get document details) andcategoryDetailLabel (Used to get category details) ofContentField also supports usingrenderParameters to control the Markdown to HTML conversion behavior. This design ensures the unity and flexibility of rendering logic when handling different types of content.