How can you reference common header, footer, or sidebar content in a template?

Calendar 👁️ 62

In the daily operation and maintenance of the website, we often encounter such situations: each page needs to include a unified header, a standard footer, or a fixed sidebar.If each page were to repeat this content, it would not only be inefficient but also the workload would be enormous if changes were needed.AnQiCMS (AnQiCMS) understands this pain point and therefore provides a flexible and powerful template reference mechanism to help us efficiently manage these public contents and ensure the unity and maintainability of the website.

Overview of AnQi CMS template mechanism

In Anqi CMS, all template files are unified with.htmlas a suffix, and stored in the root directory of the website/templateIn the folder. The template engine of Anqi CMS adopts a syntax style similar to Django, which makes it possible for us to organize and manage template content very flexibly.For elements that appear repeatedly on multiple pages, Anqi CMS provides several powerful methods to reference them, ensuring that you can build and maintain the website in the most efficient way possible.

Core method one: utilizingincludeEmbed tags into common segments

When you need to embed some relatively independent code segments that can be reused on different pages or modules,includeTags are your go-to tool. Imagine a public sidebar ad, a communication subscription form, or a brief contact information block, which may appear in multiple places on the website, but with relatively independent functionality and content.

Generally, these reusable code snippets are placed in a subdirectory namedpartial/such aspartial/header.html(Header),partial/footer.html(Footer) orpartial/sidebar.html(Sidebar).

It is very intuitive to reference, just use it where you need to refer{% include "partial/header.html" %}with this syntax.

If you want the referenced segment to receive some specific variables, you can usewithKeywords. For example, if you want to dynamically display a title in the page header, you can call it like this:{% include "partial/header.html" with page_title="我的网站首页" %}.header.htmlIn the template, you can use it directly.{{ page_title }}Retrieve this value and use it along with other inherited variables.

In addition, if you are unsure whether a certain public fragment file exists, you can useif_existsKeywords. This will not cause the page to error out if the file does not exist, but will be ignored by the system instead:{% include "partial/optional_ad.html" if_exists %}This method is very suitable for introducing optional or experimental content blocks.

Core method two: utilizingextendsTag-based template inheritance

Definition of the overall website layout,extendsTags provide a more powerful template inheritance mechanism. This is like designing a 'master page' or 'skeleton' for a website, where you can define all shared page structures, such as headers, main navigation, footer, and copyright information, in a basic template (usually namedbase.htmlorlayout.html).

In the basic template, you will useblocktags to define areas that can be filled or overwritten by child templates, such as{% block page_title %}{% endblock %}used to define the page title area, or{% block main_content %}{% endblock %}used to define the main content area of the page.

Any template that inherits this base template, for exampleindex.htmlorarticle_detail.htmlonly needs to be declared at the beginning of the file{% extends 'base.html' %}then you can use the same name to access itblockLabel to fill in or overwrite the corresponding area content. It is not overwritten by the template.blockArea, it will automatically display the default content of the parent template.

This inheritance method greatly simplifies the page structure management. When you need to adjust the header or footer, just modify

Related articles

What template file types and directory structures does AnQi CMS support to organize displayed content?

AnQi CMS provides high flexibility and strong organizational capabilities in content display, which is mainly reflected in its support for template file types and directory structures.Understanding these conventions and mechanisms can help you customize the appearance and content layout of the website more efficiently. ### The core structure and conventions of template files Firstly, AnQi CMS will统一存放 all template files used for front-end display in the root directory of the site under the `/template` folder.Each independent website theme or template set should have its own folder in this directory

2025-11-08

How to set up independent template files for specific pages or content types?

In website operation, we often encounter situations where we need to design a unique display style for certain pages or content types.Perhaps the product detail page needs a more attractive layout, or some special topic article needs to break the conventional style to highlight its importance, or a single-page 'About Us' needs to showcase the brand characteristics.AnQi CMS deeply understands this personalized need, providing flexible and powerful template customization capabilities, allowing you to easily set up exclusive template files for different content, thereby achieving more refined content presentation and brand image management.--- ###

2025-11-08

How to customize the display layout and style of AnQi CMS

Customizing the display layout and style of website content in AnQi CMS is an indispensable part of building a website that is both beautiful and efficient.The system provides a rich set of tools and flexible mechanisms, allowing users to fully control the visual presentation of the website from content structure, template selection to detailed style. ### Core Foundation: Flexible Content Model and Custom Backend The display of website content first depends on its inherent structure. One of the advantages of AnQi CMS is that it provides the 'flexible content model' feature.

2025-11-08

How to display different types of data (such as) through the AnQi CMS custom content model?

When building a website, we often encounter situations where the content is not just simple 'articles' or 'products'.The traditional website content management system is often limited to a few predefined content types, which seems inadequate when facing diverse information display needs.AnQiCMS (AnQiCMS) is well-versed in this field, providing you with a powerful tool for easily handling various data displays through its flexible custom content model function.

2025-11-08

How to correctly render Markdown editor content on the frontend page in HTML?

## AQS CMS Markdown content: How to perfectly present on the front-end page?In content creation, Markdown, with its concise and efficient syntax, has been favored by a wide range of content creators.AnQi CMS knows this and therefore provides strong Markdown editor support.But how can you ensure that the Markdown content you edit in the background is rendered correctly and beautifully on the website's frontend page?Behind this involve several key links, understanding them can help you manage the website content more skillfully.

2025-11-08

How to display mathematical formulas and flowcharts on AnQiCMS web pages?

Today, with the increasingly rich digital content, it often seems inadequate to convey complex information solely through text.Especially in fields such as science, technology, and education, mathematical formulas and flowcharts are the key to expressing rigorous logic and clear steps. 幸运的是,AnQiCMS provides a simple and powerful way to easily integrate and display these professional contents on your web page. This article will introduce in detail how to use the Markdown editor and third-party libraries on your AnQiCMS website to achieve perfect presentation of mathematical formulas and flowcharts.

2025-11-08

How to display the document title, publish time, and view count on the document detail page?

Manage website content in AnQi CMS and ensure its accurate and beautiful display on the front-end page, which is the core of daily operation work.For each document detail page, clearly presenting the title, publication time, and views of the document can not only effectively improve user experience, but is also an important link in the transmission of content information.The AnQi CMS provides powerful and flexible template tags, allowing us to easily meet these requirements. ### Locate the document detail page template To modify the display content of the document detail page, we first need to find the corresponding template file.In AnQi CMS template structure

2025-11-08

How to call and display the cover image, thumbnail, or group image of a specified document?

It is crucial to have visually appealing content when building and operating a website.AnQiCMS provides a flexible way to manage and display the images of documents (including articles, products, etc.), whether as an eye-catching cover, a clever thumbnail, or a colorful group photo.Understand how to correctly call these images, which can help you better design and optimize the user experience of the website.AnQiCMS provides several main image fields for different content types, which have clear uses in the template: * **Cover logo (Logo)**

2025-11-08