在twig中获取数组对象值

时间:2014-07-11 08:13:35

标签: php twig

您好我有一个带有stdClass对象的数组,该数组是变量($ variable)

stdClass Object
(
    [attributes] => stdClass Object
        (
            [modTime] => 2014-07-01-10:35
            [status] => current
        )

    [agentID] => 26721
    [clientID] => siggroup
    [uniqueID] => 6660337
    [authority] => stdClass Object
        (
            [attributes] => stdClass Object
                (
                    [value] => exclusive
                )

        )

    [underOffer] => stdClass Object
        (
            [attributes] => stdClass Object
                (
                    [value] => no
                )

        )
)

如果是php,我可以通过以下代码调用underOffer:

echo $variable->underOffer->attributes->value;

请帮帮我,怎么用树枝打电话呢? 提前谢谢

1 个答案:

答案 0 :(得分:0)

{% set property_uo = wp.get_post_meta(post.ID, '_property_object', TRUE) %}
{% set check_for_uo = wp.json_decode(property_uo) %}
{% if check_for_uo.underOffer.attributes.value == 'yes' %}
do something                            
{% else %}

这就是我所做的,我认为它是在wordpress主题(realia)中预先定义的,感谢帮助每个人