4

Core PHP で Mustache テンプレートを使用して、PHP ページをテンプレートに変換しています。今、次のようなテンプレートでスイッチケースを使用したい:

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

?>

同様の口ひげの翻訳は何ですか?前もって感謝します

4

2 に答える 2

5

switch ステートメントから 1 つの値を出力する以上のことを行う必要がある場合、最も簡単な回避策は、一連のブール値 (状態ごとに 1 つ) を作成することです: isPendingisInactiveなど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 <a href="/active/{{cardId}}">here</a> to reactivate it.
{{/isInactive}}
于 2013-10-25T14:06:10.017 に答える
3

switch ステートメントは、次のように php に記述します。

phpで

$card_status = null;
switch ($gift_card['FlagStatus']) {
        case 'P': 
            $card_status = "Pending";
            break;
        case 'A':
            $card_status =  "Active";
            break;
        case 'I':
            $card_status = "Inactive";
            break;
    }

render_template('giftcard_stuff', array('card_status'=>$card_status);

テンプレートでは

<div>The status of this gift card is: {{card_status}}</div>

そのようなフラグをドロップダウンに入れるようなことをしようとすると、事態はさらに複雑になります。その場合、次のように、事前に配列を書き出す必要があります。

$status_dropdown = [
    ['flag_display'=>'Pending', 'flag'=>'P'],
    ['flag_display'=>'Active', 'flag'=>'A'],
    ['flag_display'=>'Inactive', 'flag'=>'I'],
];
于 2013-01-24T23:12:55.903 に答える