我在Core PHP中使用Mustache模板将PHP页面转换为模板.现在我想在模板中使用switch case,如:
switch ($gift_card['FlagStatus']) {
case 'P':
echo "Pending";
break;
case 'A':
echo "Active";
break;
case 'I':
echo "Inactive";
break;
}
?>
什么应该是类似的胡子翻译?
提前致谢
解决方法:
如果您需要做的不仅仅是从switch语句输出单个值,最简单的解决方法是创建一系列布尔值,每个状态对应一个:isPending,isInactive,isActive等,然后为每个可能性使用单独的部分:
{{#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 here to reactivate it.
{{/isInactive}}
标签:php,switch-statement,mustache
来源: https://codeday.me/bug/20190729/1571584.html