【问题标题】:Twig: Displaying Stripe Customer CardsTwig:显示条纹客户卡
【发布时间】:2015-10-03 14:00:16
【问题描述】:

我在 Twig 中显示客户卡片时遇到了一些问题。我可以用这段代码做 PHP:

$card = \Stripe\Customer::retrieve($cu->cus_id)->sources->all(['object' => 'card']);

$i = 0;

foreach ($card["data"] as $cd) {

    echo $card["data"][$i]->brand . " - " . ucwords($card["data"][$i]->funding) . " Card: " . $card["data"][$i]->last4;
    if($i == 0){
        echo " (Default)";
    }
    echo "<br />";
    $i++;
}

但我需要在 Twig 模板中输出。我尝试了以下方法:

 {% for data in cards|keys %}
     {{ card["data"][loop.index].last4 }}
 {% endfor %}

但这根本不输出任何东西。

我正在使用 Slim PHP 框架。

【问题讨论】:

    标签: php twig stripe-payments slim


    【解决方案1】:

    您可以轻松地将 PHP 转换为 Twig。

    我不知道这个管道 (cards|keys) 是如何执行的,但我确信它在官方文档 here 中有描述。

    {% set i = 0 %}
    
    {% for cd in card.data %}
        {{ cd.brand ~ ' - ' ~ cd.funding ~ ' Card: ' ~ cd.last4 }}
    
        {{ i == 0 ? ' (Default)' : '' }}
        <br />
    
        {% set i = i + 1 %}
    {% endfor %}
    

    它没有经过测试,但应该可以工作。

    【讨论】:

      猜你喜欢
      • 2014-04-25
      • 2015-11-10
      • 2017-02-23
      • 2018-11-24
      • 2021-01-25
      • 2019-11-03
      • 2021-10-20
      • 2021-03-24
      • 2017-11-02
      相关资源
      最近更新 更多