Template creation in progress, how do the public code (bash.html) and snippet directory (partial/) affect the page display?

Calendar 👁️ 66

In Anqi CMS, when we start to build or modify website templates, we come across some core files and directory structures, including public code filesbash.htmland code snippets directorypartial/plays a crucial role in the final display of the page.They are not just a simple pile of template files, but also the 'skeleton' and 'building blocks' that make up the structure and content display logic of a website, allowing our website to maintain consistency while having a high degree of flexibility and maintainability.


The foundation of the website: Public Code (bash.html)

Imagine building a house, we first construct a strong frame, including the foundation, load-bearing walls, and roof. In the world of Anqi CMS templates,bash.htmlIt plays the role of this 'master template' or 'basic framework'. It is the top-level layout file of your website, defining the common structure that all pages will share.

Generally,bash.htmlContains parts that appear on every page, such as:

  • Website Header (Header): Including Logo, main navigation menu, search box, etc.
  • Website Footer (Footer): Copyright information, filing number, links, contact information, etc.
  • Overall layout framework: For example<head>Partly imported CSS and JavaScript files, the overall container structure of the page, reserved positions for the sidebar area, and so on.

When you designbash.htmlWhen, in fact, it is setting a unified appearance and interaction foundation for the entire website. Other specific page templates (such as the home pageindex.html, article detail pagedetail.html, list pagelist.htmlIt is not built from zero, but through{% extends 'bash.html' %}tags to "inherit" this common skeleton.

Inheritancebash.htmlThe page will default to having all the content it defines. At the same time,bash.htmlwill be used{% block ... %}{% endblock %}An element to define an area that can be "filled" or "overwritten" by child pages, such as{% block content %}Used to place the main content of the page,{% block title %}Used to set the page title. This way, each child page only needs to focus on its unique "content", without needing to rewrite the common "frame" code.

Therefore,bash.htmlDirectly determines the website'sGlobal consistency. Any forbash.htmlThe modification, such as adjusting the navigation style or adding a global script, will immediately reflect on all pages inheriting it, greatly improving development efficiency and brand consistency.


Crafty building blocks: Code snippet directory (partial/)

If we saybash.htmlis the main framework of the website, thenpartial/The files in the directory are the 'building blocks' or 'code snippets' that make up the page details.This directory is used to store those codes that can be reused on multiple pages but are not part of the global 'skeleton' components.

typicalpartial/Files include:

  • Sidebar (Sidebar)May contain popular articles, latest comments, ad spaces, etc.
  • Breadcrumb navigation (Breadcrumb): Display the current page's position in the website hierarchy.
  • Social sharing button: Allow users to share content to different social platforms.
  • Common fields of the contact formIf multiple pages have similar forms, you can extract common fields.
  • Single item in the article list.: To maintain style consistency, the display form of each article in the list can be defined as a snippet.

These code snippets are used through{% include 'partial/文件名.html' %}The tag is introduced into any page that needs it. For example, you can introduce it on the article detail page and the category list pagepartial/sidebar.htmlto display the same sidebar content

partial/The value of the table of contents lies in itsModular and reusable. When you need to modify the sidebar layout or functionality, just editpartial/sidebar.htmlThis file, all the pages that reference it will be updated synchronously, avoiding the trouble of repetitive modifications on multiple pages.

Even better, Anqi CMS allows you to pass through code snippets bywithThe tag passes specific data to it.For example, you can introduce a comment form snippet and tell it which article's comment it is.This makes these 'building blocks' both general and intelligent, able to display different content based on the context of different pages.


Collaborative work: integration of the whole and the details

bash.htmlandpartial/The catalog is an indispensable partner in the design of Anqi CMS templates, working together to shape the final page display effect of the website.

  • bash.htmlFirstly, the overall layout of the website and the common elements of all pages were set, laying a solid foundation for the website.
  • Based on this, each page template inheritsbash.htmland is built upon its{% block content %}Insert the unique content of this page in the area.
  • And this unique content of the page will often be used through{% include ... %}tags, frompartial/Introduce various ingenious code snippets from the catalog, fill in details, enrich functions.

This hierarchical, modular design approach makes template creation orderly.We can accurately control from the macro page structure to the micro element details, ensuring that the website maintains high-quality presentation and low maintenance costs during rapid iteration.

By reasonable planningbash.htmlandpartial/Catalog, your secure CMS website can not only have a clear and consistent user experience, but also make future functional expansion and content updates easier and more convenient.


Frequently Asked Questions (FAQ)

1. Can I usebash.htmldirectly{% include ... %}Tag to introducepartial/the code snippet in it?Of course you can.In fact, this is a very common practice!partial/latest_news.html, then directly inbash.htmlsomeblockInternal or fixed area through{% include 'partial/latest_news.html' %}Introduced. In this way, this widget will appear on all inheritedbash.htmlpages.

2. If I modifiedbash.htmlorpartial/Why is the file in the directory not updated immediately on the website page?This is likely a caching issue.AnQi CMS in order to improve website performance, will cache template files.After you modify the template file, you may need to manually clear the system cache to see the latest effect.You can find the 'Update Cache' feature in the Anqi CMS backend, click to execute it.Sometimes, the browser's own cache may also cause delays, you can try to force refresh the page (Ctrl+F5 or Cmd+Shift+R) or clear the browser cache.

3. How topartial/Pass data to the code snippet in the directory to display the content of different pages?You can access{% include ... with key=value %}by such syntax to pass data to code snippets. For example, if you have apartial/comment_form.htmlto display the comment form, you can introduce it like this on the article detail page:{% include 'partial/comment_form.html' with article_id=archive.Id %}.comment_form.htmlInside, you can pass through{{ article_id }}To get and use the article ID passed in. This way, the code snippet can dynamically display content according to the context, which is very flexible.

Related articles

How does the AnQiCMS v2.0.1 version's new article content batch replacement and paraphrasing feature change the display of content?

## AnQiCMS v2.0.1: How do the content renewal, batch replacement and pseudo-original function change the website display?Today, in the increasingly fierce digital marketing, website content must not only be of high quality but also maintain freshness and flexibility.For content operators, how to efficiently manage and optimize a large amount of content while ensuring its good performance in search engines and in front of users is always a challenge.AnQiCMS v2.0.1 version brings the batch replacement and paraphrasing function of article content, which is designed to solve these pain points, and they are implemented in an intelligent way

2025-11-07

How do the new model features in AnQiCMS v2.1.1 affect the display logic of articles and products?

Since its launch, AnQiCMS has been favored by users for its concise, efficient, and flexible features.In the latest v2.1.1 version, we welcome a major feature update - a brand new 'Model' feature.This seemingly technical improvement actually has a profound impact on the way we publish and display website content on a daily basis, especially for core content types such as articles and products.Model Function: Blueprint of Content Structure In simple terms, "model" is like a blueprint or skeleton for content. In the past

2025-11-07

How to configure AnQiCMS Apache reverse proxy to correctly display website content?

AnQiCMS is an efficient content management system developed based on the Go language, which usually runs on a specific port of the server, such as the default port 8001.In order for users to access the website through common domain names instead of adding a port number at the end of the address, we need to configure a reverse proxy.

2025-11-07

How does the adaptive template, code adaptation, and PC + mobile mode affect the display of content on different devices?

AnQiCMS content management system provides powerful flexibility in content presentation, especially for display effects on different devices.It supports three template modes of "adaptive", "code adaptation", and "PC + independent mobile site", allowing us to finely control the display of content on computers, tablets, and mobile phones according to specific needs.Understanding the working principle of these patterns is crucial for ensuring user experience and optimizing website performance.First, let's understand **Adaptive Mode**.In adaptive mode, the website uses a set of templates and styles

2025-11-07

How to configure specific template files for the homepage, detail page, list page, etc. of AnQiCMS to control the display?

AnQiCMS, with its high efficiency and flexible customization features developed in the Go language, provides strong control over the display of website content.Whether you are operating a small and medium-sized enterprise website, a personal blog, or need to manage multiple sites, understanding how to configure exclusive templates for different pages is the key to improving website personalization and user experience.In AnQiCMS, the core of content display lies in the template files.These files determine the visual layout, content formatting, and interactive elements of the website.AnQiCMS uses a syntax similar to Django template engine

2025-11-07

What is the impact of folder organization mode and flat file organization mode on template production and content display?

When building website templates in AnQi CMS, the organization of template files is one of the core issues you need to pay attention to.AnQi CMS provides two main template organization modes: **Folder Organization Mode** and **Flattened File Organization Mode**.These two modes have their own characteristics, and their choice will directly affect the efficiency of your template creation and the final presentation of the content.Understand their differences and impacts, which can help you make more informed decisions based on project needs.### Folder Organization Mode

2025-11-07

How to get and display the website global information using the AnQiCMS system settings label `system`?

In website construction and daily operation, we often encounter situations where we need to display some global information, such as the name of the website, Logo, filing number, contact information, etc.This information runs through the entire website and needs to be consistent across multiple pages.AnQiCMS provides an extremely convenient way to handle this type of global information, which is through its built-in `system` template tag.

2025-11-07

How to dynamically display the `contact` label of the company contact information?

In website operation, clear, accurate and easy-to-update business contact information is a crucial link.Imagine if you need to update your contact phone number or email, do you need to manually modify every web page that contains this information?This is not only time-consuming and labor-intensive, but may also lead to inconsistent information due to omissions, affecting user experience and brand image. AnQiCMS (AnQiCMS) is well-versed in this, and to address this pain point, it has specially provided the **contact label `contact`**.

2025-11-07