Joomla的htmlhelper如何将<image>标签嵌套到<a>标签中。

huangapple go评论68阅读模式
英文:

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:

&lt;div class=&quot;row&quot;&gt;
	&lt;a href=&quot;images/big/768.jpg&quot; data-toggle=&quot;lightbox&quot; data-gallery=&quot;example-gallery&quot; class=&quot;col-sm-4&quot;&gt;
		&lt;img src=&quot;images/small/600.jpg&quot; class=&quot;img-fluid&quot;&gt;
	&lt;/a&gt;
	&lt;a href=&quot;images/big/769.jpg&quot; data-toggle=&quot;lightbox&quot; data-gallery=&quot;example-gallery&quot; class=&quot;col-sm-4&quot;&gt;
		&lt;img src=&quot;images/small/601.jpg&quot; class=&quot;img-fluid&quot;&gt;
	&lt;/a&gt;
	&lt;a href=&quot;images/big/770.jpg&quot; data-toggle=&quot;lightbox&quot; data-gallery=&quot;example-gallery&quot; class=&quot;col-sm-4&quot;&gt;
		&lt;img src=&quot;images/small/602.jpg&quot; class=&quot;img-fluid&quot;&gt;
	&lt;/a&gt;
&lt;/div&gt;

I wrote this code, where $customFields['photos']->rawvalue is an array that contains the list of images filenames

&lt;div class=&quot;row&quot;&gt;
	&lt;?php
		foreach($customFields[&#39;photos&#39;]-&gt;rawvalue as $foto) { ?&gt;
			&lt;?php 
				echo HTMLHelper::_(&#39;link&#39;, &#39;images/fiera/big/&#39;.$foto, &#39;&#39;, [&quot;class&quot; =&gt; &quot;col-sm-6 col-md-4&quot;, &quot;data-toggle&quot; =&gt; &quot;lightbox&quot;, &quot;data-gallery&quot; =&gt; &quot;fiera&quot;]);
				echo HTMLHelper::_(&#39;image&#39;, &#39;images/fiera/small/&#39;.$foto, $foto, [&quot;class&quot; =&gt; &quot;img-fluid&quot;], false, 0); 
			?&gt;	
	&lt;?php } ?&gt;
&lt;/div&gt;

The problem is that in this way the <image> tag is not inside <a> tag; the actual autput is this:

&lt;div class=&quot;row&quot;&gt;
	&lt;a href=&quot;/images/fiera/big/10_fiera_big.jpg&quot; class=&quot;col-sm-6 col-md-4&quot; data-toggle=&quot;lightbox&quot; data-gallery=&quot;fiera&quot;&gt;&lt;/a&gt;&lt;img class=&quot;img-fluid&quot; src=&quot;/images/fiera/small/10_fiera_big.jpg&quot; alt=&quot;10_fiera_big.jpg&quot;&gt;						
	&lt;a href=&quot;/images/fiera/big/11_fiera_big.jpg&quot; class=&quot;col-sm-6 col-md-4&quot; data-toggle=&quot;lightbox&quot; data-gallery=&quot;fiera&quot;&gt;&lt;/a&gt;&lt;img class=&quot;img-fluid&quot; src=&quot;/images/fiera/small/11_fiera_big.jpg&quot; alt=&quot;11_fiera_big.jpg&quot;&gt;							
&lt;/div&gt;

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']); ?>
英文:
&lt;div class=&quot;row&quot;&gt;
    &lt;?php foreach ($customFields[&#39;photos&#39;]-&gt;rawvalue as $foto) : ?&gt;
        &lt;?php echo HTMLHelper::_(&#39;link&#39;, HTMLHelper::_(&#39;image&#39;, &#39;images/fiera/small/&#39;.$foto, $foto, [&#39;class&#39; =&gt; &#39;img-fluid&#39;], false, 0), &#39;images/fiera/big/&#39;.$foto, [&#39;class&#39; =&gt; &#39;col-sm-4&#39;, &#39;data-toggle&#39; =&gt; &#39;lightbox&#39;, &#39;data-gallery&#39; =&gt; &#39;fiera&#39;]); ?&gt;
    &lt;?php endforeach; ?&gt;
&lt;/div&gt;

huangapple
  • 本文由 发表于 2023年6月15日 20:19:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76482403.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定