[英]PHP code inside echo
I have following code which displays the price in Magento. 我有以下代码显示Magento的价格。
<?php echo $this->getPriceHtml($_product); ?>
I have to put this code inside echo instead and I can't get it to work. 我必须将此代码放入echo中,但无法正常工作。
I am trying 我在尝试
echo "$this->getPriceHtml ($_product)";
It just displays () on the page. 它仅在页面上显示()。
I tried other combinations and I can't come up with anything else. 我尝试了其他组合,但我无能为力。 What am I doing wrong?
我究竟做错了什么?
Using single quotes will prevent $vars to be interpreted: 使用单引号将阻止$ vars的解释:
echo '$this->getPriceHtml ($_product)';
Or escape the $ sign: 或转义$符号:
echo "\$this->getPriceHtml (\$_product)";
http://php.net/manual/en/language.types.string.php http://php.net/manual/en/language.types.string.php
Or if by echo-ing you mean that you want to get something like 或者,如果通过回声表示您想要获得类似
The price is 123.00
then do: 然后做:
echo "The price is {$this->getPriceHtml($_product)}";
or even : 甚至 :
echo sprintf("The price is %s", $this->getPriceHtml($_product));
why not you are using this ? 为什么不使用这个呢?
$_product->getFinalPrice() or $ _product-> getFinalPrice()或
if you want in formatted order then why you are not using this number_format($pr->getPrice(), 2) 如果要按格式排序,那么为什么不使用此number_format($ pr-> getPrice(),2)
and if you want price with currency format then you can use this also Mage::helper('core')->currency($pr->getPrice()); 如果您想使用货币格式的价格,则也可以使用Mage :: helper('core')-> currency($ pr-> getPrice());
Hope it will help you. 希望对您有帮助。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.