开发者

PHP string question

This is probably a very simple one to be answered...

I have a piece of code which I need to pull a certain piece of information.

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('XXXX')->toHTML();?>

For this to work I need the XXXX part to pull the result of the following query:

<?php echo $_product->getAttributeText('warranty') ?>

So 开发者_C百科the output from the above query will then be the information needed to go in to XXXX.

This markup is completely wrong below but should demonstrate the idea I am trying to achieve:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('<?php echo $_product->getAttributeText('warranty') ?>')->toHTML();?>


You just have a redundant PHP opening <?php inside the code. You are already in PHP context so you can do that call directly.

<?php  echo
$this->getLayout()->createBlock('cms/block')->setBlockId($_product->getAttributeText('warranty'))->toHTML();?>

However, this is quite complicated and difficult to debug. I would split it in several lines and use variables... remember that you can do it in that context, you are not bound to do everything in one line only :)


Maybe as simple as:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId($_product->getAttributeText('warranty'))->toHTML();?>

If not then I would very much like to know what kind of var (array, int, string, double etc) the setBlockId function needs and what $_product->getAttributeText returns.


echo $this->getLayout()->createBlock('cms/block')->setBlockId($_product->getAttributeText('warranty'))->toHTML();?>


<?php 
 echo $this->getLayout()
          ->createBlock('cms/block')
          ->setBlockId($_product->getAttributeText('warranty'))
          ->toHTML();
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜