When operating your website, if you provide membership or VIP services, it is crucial for users to clearly understand their VIP status, when it will expire, and how to renew, which is essential for improving user experience and member retention.English CMS (EnglishCMS) with its flexible template engine and powerful user management features, allows you to easily implement these features in website templates.

We all know that Aanqi CMS has built-in perfect user group management and VIP system, which allows us to conveniently set different levels of user permissions and paid content.How can one intuitively understand all this when the user sees their VIP status?ExpireTimeField.

UnderstandExpireTimeField

In the Auto CMS, each user has a relatedExpireTimeField, it records the expiration time of the user's VIP service.This field stores a standard timestamp (Unix timestamp), representing the moment when the VIP service expires.

To get this information in the template, we need to useuserDetailThis template tag. It can retrieve the detailed information of the current or specified user. Usually, we would do it like this to get the details of the currently logged-in user.ExpireTime:

{% userDetail userProfile with id=user.Id %}
{% set expireTime = userProfile.ExpireTime %}

Here,user.Idusually represents the ID of the currently logged-in user.userProfileIt is an object that contains all the detailed information of the user.userProfile.ExpireTimeThen we got this key timestamp.

This timestamp is not intuitive when displayed directly, so we need to convert it to a date format that humans can understand. The Anqi CMS providesstampToDateThis powerful filter (or function tag) can format timestamps into any date and time format you want. For example, if we want to format it as "2006-01-02 15:04", we can use it like this:

{% set formattedExpireTime = stampToDate(expireTime, "2006年01月02日 15时04分") %}

Determine the core logic of VIP status

Now we have the user's VIP expiration timeexpireTimeand its readable formatformattedExpireTime. Next, we need to get the current time to compare withexpireTimeTo compare. The template of Anqi CMS providesnowtags to get the current time. For convenience of comparison, we usually also convert it to a timestamp.

{% set current_timestamp_str = now "20060102150405" %}
{% set current_timestamp = current_timestamp_str|integer %}

Here we utilizenowLabel outputs a pure numeric date and time string (e.g., "20231027103000"), and then throughintegerthe filter converts it to a comparable integer timestamp.

With these two timestamps, we can use it in the template.if/elif(else if) andelseLogic judgment tags can be used to display different contents according to VIP status.

Basic judgment logic can be divided into three cases:

  1. VIP Status Normal: expireTimegreatercurrent_timestamp.
  2. VIP Expiring Soon: expireTimegreatercurrent_timestampBut it is also within a predefined 'Expiring Soon' time range (such as within 7 days).
  3. VIP Expired: expireTimeLess than or equal tocurrent_timestamp.

In order to judge "about to expireFor example, if you want to determine whether something is expired within 7 days, you can calculate the current timestamp plus the number of seconds corresponding to 7 days (7 * 24 * 60 * 60).

{% set seven_days_in_seconds = 7 * 24 * 3600 %}
{% set seven_days_later_timestamp = current_timestamp|add:seven_days_in_seconds %}

Here we cleverly utilize itaddFilter to calculate the addition of timestamps.

Implement the display of different states in the template

Now, let's combine these logic to see how to design different displays for these three states.

Assuming we want to display this information on the user's personal center page, we can refer to the following structure:

{% set formattedExpireTime = stampToDate(expireTime, "2006年01月02日") %} {# 格式化到期日期 #}

{% set current_time_str = now “20060102150405” %} {# Get the current time (formatted as a pure numeric string) #} {% set current_timestamp = current_time_str|integer %} {# Convert to an integer timestamp #}

{% set seven_days_in_seconds = 7 * 2 %} English translation: {% set seven_days_in_seconds = 7 * 2 %} The translation of "auto" is "English".