search
HomeCMS TutorialDEDECMSHow to use if for multi-branch judgment in DEDE template

How to use if for multi-branch judgment in DEDE template

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

When we use dede as a template, We often encounter situations where different content needs to be displayed separately based on a certain conditional judgment, which is the multi-branch judgment in the dede template. For example, typically, we need to display different risk prompt icons according to the different values ​​of the risk level field risklevel in the risk management database table. As shown in Figure 1.

How to use if for multi-branch judgment in DEDE template

The icons in front of the investment project names in the red box represent different risk levels. There are 4 risk levels: AA, D, E, and HR. What is saved in the database table is one of these four level values, as shown in Figure 2.

How to use if for multi-branch judgment in DEDE template

Our risk level field risklevel can get its value in the list template, because we have set this field in the content model to allow it to be included in the list template value.

As shown in Figure 3.

How to use if for multi-branch judgment in DEDE template

In this way, we can easily get the value of the risk level through

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

in the list template.

But the prompt icons corresponding to our different risk levels are located in the picture directory, and the names of these prompt picture files have no rules, so we need to use if judgment to set different values ​​according to the different risk levels. The prompt image path.

So how should we judge?

You need to use the [field:array] tag, so how should we judge it?

We first want to introduce to you a very useful dede tag: [field:array] tag, which is the abbreviation of the tag {dede:field name='array' /}, which is used in lists Inside the tag, for example: {dede:list} tag, {dede: arclist} and other tags.

We know that inside the list tag we can get the value of a database table field in the form of [field:field name/], then when we want to make branch judgments, for example: based on risk Different level values ​​result in different icon paths. At this time, we must use the [field:array] tag. The [field:array] tag represents a record in the database table obtained by query. 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}

It 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 above code It is a branch conditional output statement. @me represents the output variable. When you first enter the label field:array, @me represents a record in the database, and its data type is an array. We judge based on the value of risklevel, so as to @me is set to different values. When exiting the tag field:array, the value of @me will be displayed in the original position.

The function of this tag is very powerful. It is suitable for our most common scenarios. When we need to perform if branch judgment based on specific conditions to display different content in the template page, use the field:array tag. It will bring us great convenience.

The above is the detailed content of How to use if for multi-branch judgment in DEDE template. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment