在 echo 语句中回显字符串?

发布于 2024-11-08 20:10:08 字数 568 浏览 0 评论 0原文

这可能是一个非常简单的问题......

我有一段代码,我需要提取某条信息。

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

为此,我需要 XXXX 部分来提取以下查询的结果:

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

因此上述查询的输出将是进入 XXXX 所需的信息。

下面的标记是完全错误的,但应该展示我想要实现的想法:

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

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 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();?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

剩一世无双 2024-11-15 20:10:08

您只是在代码中添加了一个多余的 PHP 开头

<?php  echo
$this->getLayout()->createBlock('cms/block')->setBlockId($_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 :)

花想c 2024-11-15 20:10:08

也许很简单:

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

如果没有,那么我非常想知道 setBlockId 函数需要什么样的 var(数组、int、字符串、double 等)以及 $_product->getAttributeText 返回什么。

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.

萌吟 2024-11-15 20:10:08
echo $this->getLayout()->createBlock('cms/block')->setBlockId($_product->getAttributeText('warranty'))->toHTML();?>
echo $this->getLayout()->createBlock('cms/block')->setBlockId($_product->getAttributeText('warranty'))->toHTML();?>
后来的我们 2024-11-15 20:10:08
<?php 
 echo $this->getLayout()
          ->createBlock('cms/block')
          ->setBlockId($_product->getAttributeText('warranty'))
          ->toHTML();
?>
<?php 
 echo $this->getLayout()
          ->createBlock('cms/block')
          ->setBlockId($_product->getAttributeText('warranty'))
          ->toHTML();
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文