In the daily content operation of AnQiCMS, we usually hope that the system can automatically render Markdown format content into beautiful HTML for direct display on the website.However, in certain specific scenarios, such as when you may need to export the original Markdown text to other platforms, or to directly display Markdown code blocks on a page (for example, in tutorials or technical articles), or to provide pure Markdown data for API interfaces, it is particularly important for AnQiCMS to display the original Markdown text instead of the rendered HTML.

AnQiCMS provides flexible control options, allowing you to achieve this requirement at the content output level.

Understand the default rendering mechanism of AnQiCMS

Firstly, we need to understand the basic logic of AnQiCMS handling Markdown content.When you enter 'Content Settings' in the 'Global Settings' backstage and enable the Markdown editor, the system will automatically parse and render the Markdown content edited through the editor into HTML by default when it is output on the front-end page.This is convenient and efficient for most content display scenarios.

However, if you wish to override the default behavior at a specific display location or for specific content, AnQiCMS allows you to fine-tune control through template tag parameters.

Control the rendering behavior of Markdown in the template

To display the Markdown original text instead of rendering it as HTML, the core lies in modifying your website template file. AnQiCMS handles core content types such as "Document Details", "Category Details", and "Single Page Details".ContentWhen the (content) field is provided, all of them have provided arenderparameter to control whether Markdown is converted to HTML.

Specifically, when you call the content in the template,ContentWhen a field is specified, it can be indicated that the system should not perform Markdown rendering by usingrenderparameter settingsfalseto instruct the system not to execute Markdown rendering.

Let's take the most common document content as an example to illustrate in detail:

  1. Locate the template file that needs to be modified:AnQiCMS template files are usually stored in the root directory of your system:/templatefolder. For example, the document detail page may be located in{模型table}/detail.htmlThe category list page may be located at{模型table}/list.htmlWhile the single page detail page may be located atpage/detail.htmland so on. You can modify the template file by using the 'Template Design' feature in AnQiCMS backend and edit it online or download it.

  2. Modify the content by calling the label:In the template, you will find similar{% archiveDetail archiveContent with name="Content" %}{{archiveContent|safe}}content calls for tags. Here,archiveContentis the variable name you specify for the content field,{{archiveContent|safe}}which is responsible for safely outputting the obtained content to the page.

    To make the system display the Markdown original, you just need to inarchiveDetail(or}categoryDetail/pageDetail)tag, addname="Content"the call withrender=falsethis parameter. The modified code will look like this:

    {# 显示Markdown原文,不进行渲染 #}
    {% archiveDetail archiveContent with name="Content" render=false %}{{archiveContent}}
    

    Or, if you are accessing directlyarchive.Contentsuch variables to retrieve content (the current document's properties can usually be accessed directly on the document detail page), the same can beContentadded after the fieldrender=falseParameters:

    {# 同样显示Markdown原文,适用于直接访问文档对象的Content属性 #}
    {{archive.Content|render:false}}
    

    It is worth noting that when you setrender=falseWhen, if your content field includes Markdown syntax, the system will directly output these Markdown texts. At this point, if your Markdown text itself contains HTML tags (such as<div>/<p>wait), and you hope that these HTML tags can be parsed normally by the browser rather than displayed as plain text, then you still need to add the closing curly brace after the output variable.|safea filter, that is{{archiveContent|safe}}But for the pure Markdown original text,|safemainly to prevent the characters such as<>from being escaped.

Application scenario example

Assume you are building a technical blog and need to display Markdown code snippets in the article instead of rendering them as HTML.You can directly paste Markdown code into the text box of the document content (for example, by enclosing the code block with three backticks).article/detail.htmlIn it, the tags of the article content will be changed to:

<div class="article-body">
    {% archiveDetail articleContent with name="Content" render=false %}{{articleContent|safe}}
</div>

This way, the Markdown code block in the article will be displayed on the page with the original Markdown syntax, and will not be rendered as code highlighting or other HTML structures.If you wish to implement Markdown rendering on the frontend (for example, using a JavaScript library), you can handle the Markdown source after obtaining it.

With this template-level control, you can flexibly decide how to display the website content, whether it's automatic rendering or showing the original text, it's all under your control.

Common Questions and Answers (FAQ)

Can I display a part of the same document as rendered HTML and another part as the original Markdown text?

This requires more complex processing.render=falseThe parameter acts on the entireContentfield. AnQiCMS itself does not have built-in functionality to convert aContentField split into parts for rendering and parts of the original text output. If you have this requirement, the usual solution is:

  • Split content field:Create two or more content fields in the content model, for exampleRenderedContentandRawMarkdownContent. When publishing content in the background, the parts that need to be rendered will be placed inRenderedContent, and the parts that need the original text will be placed inRawMarkdownContentThen call them in the template.RawMarkdownContentwhen calling the field.render=false.
  • Front-end JS rendering:Always get the original Markdown content (using)render=falseThen use a frontend JavaScript library (such asmarked.jsorshowdown.js) to process the part that needs to be rendered in the browser.

2. Disable the Markdown editor in the "Global Settings -> Content Settings" background usage setting in templatesrender=falseWhat is the difference?

Disabling the Markdown editor in the background is a global setting, which means that when editing content in the background, ContentThe field will be treated as a plain text area, no longer providing Markdown editor functionality, and the system will no longer attempt to convert on the frontend.ContentThe content field is parsed as HTML. This will affect all pages using the content model.

whilerender=falseis a local control at the template level. Even if the Markdown editor is enabled in the background and the content is written according to Markdown syntax,render=falseThe Markdown source will also be forced to be displayed during the current template output.This approach is more flexible, allowing Markdown rendering to be maintained on most pages, but obtaining the original text in specific scenarios (such as tutorial pages, API interfaces).

3. If the content field stores pure HTML code instead of Markdown, usingrender=falsewhat effects will it have?

If the content field stores pure HTML code (not Markdown), userender=falseParameters will have no negative impact.Because it will only tell AnQiCMS 'Do not try to parse Markdown', and HTML itself is not Markdown.Therefore, the system will directly output the pure HTML code you have stored.{{yourVariable|safe}}to