在Mustache模板中如何使用开关盒? [英] How to use switch case in Mustache template?

查看:66
本文介绍了在Mustache模板中如何使用开关盒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Core PHP中使用Mustache模板将PHP页面转换为模板.现在,我想在模板中使用switch case:

I'm using Mustache template in Core PHP to turn PHP pages to template. Now I want to use switch case in template like:

<?php
    switch ($gift_card['FlagStatus']) {
        case 'P': 
            echo "Pending";
            break;
        case 'A':
            echo "Active";
            break;
        case 'I':
            echo "Inactive";
            break;
    }

?>

与其类似的"Mustache"翻译应该是什么? 预先感谢

what should be its similar Mustache translation? thanks in advance

推荐答案

如果您需要做的不仅仅是从switch语句输出单个值,那么最简单的解决方法是创建一系列布尔值,每个状态一个布尔值: isPendingisInactiveisActive等,然后针对每种情况使用单独的部分:

If you need to do more than just output a single value from the switch statement, the simplest workaround is to create a series of booleans, one for each state: isPending, isInactive, isActive etc and then use separate sections for each eventuality:

{{#isPending}}
Your gift card is pending. It will be activated on {{activationDate}}.
{{/isPending}}
{{#isActive}}
Your gift card is active. Its balance is ${{balance}}.
{{/isActive}}
{{#isInactive}}
Your gift card is inactive. Go <a href="/active/{{cardId}}">here</a> to reactivate it.
{{/isInactive}}

这篇关于在Mustache模板中如何使用开关盒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆