英文:
Joomla htmlhelper how to write <image> tag nested into <a> tag
问题
以下是您需要的最终HTML代码:
<div class="row">
    <a href="images/big/768.jpg" data-toggle="lightbox" data-gallery="example-gallery" class="col-sm-4">
        <img src="images/small/600.jpg" class="img-fluid">
    </a>
    <a href="images/big/769.jpg" data-toggle="lightbox" data-gallery="example-gallery" class="col-sm-4">
        <img src="images/small/601.jpg" class="img-fluid">
    </a>
    <a href="images/big/770.jpg" data-toggle="lightbox" data-gallery="example-gallery" class="col-sm-4">
        <img src="images/small/602.jpg" class="img-fluid">
    </a>
</div>
以下是修复的PHP代码,确保<img>标签在<a>标签内:
<div class="row">
    <?php
    foreach ($customFields['photos']->rawvalue as $foto) { ?>
        <a href="<?php echo 'images/fiera/big/' . $foto; ?>" data-toggle="lightbox" data-gallery="fiera" class="col-sm-6 col-md-4">
            <?php echo HTMLHelper::_('image', 'images/fiera/small/' . $foto, $foto, ["class" => "img-fluid"], false, 0); ?>
        </a>
    <?php } ?>
</div>
这个修复会确保<img>标签在适当的<a>标签内。
英文:
I'm customizing the output of a Joomla 4 content component.
I wrote an override in Joomla template but I have an issue writing the correct html string usign htmlhelper api.
This is the final html I need:
<div class="row">
	<a href="images/big/768.jpg" data-toggle="lightbox" data-gallery="example-gallery" class="col-sm-4">
		<img src="images/small/600.jpg" class="img-fluid">
	</a>
	<a href="images/big/769.jpg" data-toggle="lightbox" data-gallery="example-gallery" class="col-sm-4">
		<img src="images/small/601.jpg" class="img-fluid">
	</a>
	<a href="images/big/770.jpg" data-toggle="lightbox" data-gallery="example-gallery" class="col-sm-4">
		<img src="images/small/602.jpg" class="img-fluid">
	</a>
</div>
I wrote this code, where $customFields['photos']->rawvalue is an array that contains the list of images filenames
<div class="row">
	<?php
		foreach($customFields['photos']->rawvalue as $foto) { ?>
			<?php 
				echo HTMLHelper::_('link', 'images/fiera/big/'.$foto, '', ["class" => "col-sm-6 col-md-4", "data-toggle" => "lightbox", "data-gallery" => "fiera"]);
				echo HTMLHelper::_('image', 'images/fiera/small/'.$foto, $foto, ["class" => "img-fluid"], false, 0); 
			?>	
	<?php } ?>
</div>
The problem is that in this way the <image> tag is not inside <a> tag; the actual autput is this:
<div class="row">
	<a href="/images/fiera/big/10_fiera_big.jpg" class="col-sm-6 col-md-4" data-toggle="lightbox" data-gallery="fiera"></a><img class="img-fluid" src="/images/fiera/small/10_fiera_big.jpg" alt="10_fiera_big.jpg">						
	<a href="/images/fiera/big/11_fiera_big.jpg" class="col-sm-6 col-md-4" data-toggle="lightbox" data-gallery="fiera"></a><img class="img-fluid" src="/images/fiera/small/11_fiera_big.jpg" alt="11_fiera_big.jpg">							
</div>
Any idea?
答案1
得分: 2
rawvalue as $foto) : ?>
'img-fluid'], false, 0), 'images/fiera/big/' . $foto, ['class' => 'col-sm-4', 'data-toggle' => 'lightbox', 'data-gallery' => 'fiera']); ?>
'img-fluid'], false, 0), 'images/fiera/big/' . $foto, ['class' => 'col-sm-4', 'data-toggle' => 'lightbox', 'data-gallery' => 'fiera']); ?>
英文:
<div class="row">
    <?php foreach ($customFields['photos']->rawvalue as $foto) : ?>
        <?php echo HTMLHelper::_('link', HTMLHelper::_('image', 'images/fiera/small/'.$foto, $foto, ['class' => 'img-fluid'], false, 0), 'images/fiera/big/'.$foto, ['class' => 'col-sm-4', 'data-toggle' => 'lightbox', 'data-gallery' => 'fiera']); ?>
    <?php endforeach; ?>
</div>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论