2013-09-28 128 views
0

我有这样的一个xml:使用如何访问Twig(Symfony)中特定节点的XML属性?

item.domain.currentPrice 

<item> 
    <domain> 
    <currentPrice currency="EUR">17.9</currentPrice> 
    </domain> 
</item> 

我可以呈现在嫩枝17.9的价值,但我怎么能访问属性“货币”来呈现呢?

item.domain.currentPrice['currency'] 

不起作用。然后我得到:

Key "curreny" in object (with ArrayAccess) of type "SimpleXMLElement" does not exist 

谁能帮我?

回答

2

您可以访问通过属性的货币属性值()方法:

{{ xml.domain.currentPrice.0.attributes.currency }} 

,你会做,在PHP:

$xml->domain->currentPrice[0]->attributes()->currency; 

其实枝杈使得从树枝代码到PHP这种转变代码和php代码最终执行。

您可以仔细检查SimpleXMLElement的API以了解您可以使用哪些方法和属性。