Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of using if to judge multi-branches in DEDE template

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the DEDE template using if for multi-branch judgment method, has a certain reference value, friends can refer to the need. I hope you all have a lot to gain after reading this article. Let's take a look at it together.

How to use if to make multi-branch judgment in DEDE template?

When we use dede as a template, we often encounter situations where different contents need to be displayed according to a certain condition judgment, that is, multi-branch judgment in dede template. For example, we typically need to display different risk warning icons according to the different values of the risklevel field in the risk management database table. As shown in Figure 1.

The icon in front of the investment project name in the red box indicates different risk levels. There are 4 risk levels: AA, D, E and HR. The database table stores one of these four grade values, as shown in Figure 2.

Our risklevel field is one that can be retrieved in the list template because we have set it in the content model to allow values in the list template.

as shown in figure 3.

In this way, we can easily get through the list template

{dede:listpagesize='10'} [field:risklevel/] {/dede:list}

to get the value of the risk level.

However, the prompt icons corresponding to different risk levels are located in the picture directory, and the names of these prompt picture files do not have any rules, so we need to set different prompt picture paths according to different values of risk levels through if judgment.

So how should we judge?

We need to use the [field:array] tag, so how do we judge?

We will first introduce a very useful dede tag: the [field:array] tag, which is a shorthand for the tag {dede:field name ='array ' /}, which is used inside list tags, such as {dede:list} tags,{dede: arclist} tags, etc.

We know that in the list tag we can get the value of a database table field in the form of [field: field name/], so when we want to make branch judgment, for example: different icon paths are obtained according to different risk level values, at this time we must rely on the [field:array] tag,[field:array] tag represents a record in the database table obtained by query, and the specific judgment code is as follows:

[field:array runphp='yes'] if(@me['risklevel']=="HR")@me="HR.png"; else if(@me['risklevel']=="D")@me="D.png"; else if(@me['risklevel']=="AA")@me="AA.png"; [/field:array] {/dede:list}

This means that if the value of the risk level field obtained by the query is HR, then HR.png will be output. If the value of the risk level field obtained by the query is D, then D.png will be output. If the value of the risk level field obtained by the query is AA, then AA.png will be output. HR.png here is just a string representing the location of the image file. You can set it to any image path. The code above is a branch conditional output statement.@me represents the output variable. When entering the label field:array,@me represents a record in the database. Its data type is array. We judge according to the value of risklevle, so @me is set to a different value. When exiting the label field:array,@me will be displayed in the original position.

This tag is very powerful, it is suitable for our most common scenarios, when we need to make if branch judgment according to specific conditions in the template page to display different content, using the field:array tag will bring us great convenience.

Thank you for reading this article carefully. I hope that Xiaobian can share the method of using if for multi-branch judgment in DEDE template to help everyone. At the same time, I hope that everyone will support you a lot. Pay attention to the industry information channel and find out if you encounter problems. Detailed solutions are waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report