在 echo 语句中回显字符串?
这可能是一个非常简单的问题......
我有一段代码,我需要提取某条信息。
<?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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您只是在代码中添加了一个多余的 PHP 开头
然而,这相当复杂且难以调试。我会将其分成几行并使用变量...请记住,您可以在该上下文中执行此操作,您不必只在一行中执行所有操作:)
You just have a redundant PHP opening <?php inside the code. You are already in PHP context so you can do that call directly.
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 :)
也许很简单:
如果没有,那么我非常想知道 setBlockId 函数需要什么样的 var(数组、int、字符串、double 等)以及 $_product->getAttributeText 返回什么。
Maybe as simple as:
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.