我需要一个if语句,以便仅在getBlockLink存在的情况下创建包装锚链接。到目前为止,所有尝试都失败了。任何php向导都能为我提供解决方案吗?
<div class="<?php echo $this->getSize(); ?>">
<a href="<?php echo $this->getBlockLink(); ?>">
<span class="grid grid--full">
<span class="grid__item <?php echo $this->getTextPosition() . ' ' . $this->getTextWidth(); ?>">
<?php echo $this->getBlockFormattedContent(); ?>
</span>
<img src="<?php echo $this->getImage(); ?>">
</span>
</a>
</div>
这样的东西应该可以工作:
<div class="<?php echo $this->getSize(); ?>">
<?php if (!empty($this->getBlockLink())) : ?>
<a href="<?php echo $this->getBlockLink(); ?>">
<?php endif; ?>
<span class="grid grid--full">
<span class="grid__item <?php echo $this->getTextPosition() . ' ' . $this->getTextWidth(); ?>">
<?php echo $this->getBlockFormattedContent(); ?>
</span>
<img src="<?php echo $this->getImage(); ?>">
</span>
<?php if (!empty($this->getBlockLink())) : ?>
</a>
<?php endif; ?>
</div>
这似乎适用于
<div class="<?php echo $this->getSize(); ?>">
<?php if($this->getBlockLink()): ?>
<a href="<?php echo $this->getBlockLink(); ?>">
<?php endif; ?>
<span class="grid grid--full">
<span class="block_content grid__item <?php echo $this->getTextPosition() . ' ' . $this->getTextWidth(); ?>">
<?php echo $this->getBlockFormattedContent(); ?>
</span>
<img src="<?php echo $this->getImage(); ?>">
</span>
<?php if($this->getBlockLink()): ?>
</a>
<?php endif; ?>