|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jonal Smarty Rookie
Joined: 16 Apr 2021 Posts: 11
|
Posted: Wed May 19, 2021 9:15 am Post subject: Capture not working as expected |
|
|
I think I got something wrong here, but for some reason the following isn't working as I thought it would.
Code: | {capture name="capture_1"}
<div class="div_1">
<div class="div_2">
<div class="div_3">
</div>
</div>
</div>
{/capture}
{if $Data.link}
<a href="{$Data.link}">
{$smarty.capture.capture_1}
</a>
{else}
{$smarty.capture.capture_1}
{/if}
|
My expected output would be:
Code: | <div class="div_1">
<div class="div_2">
<div class="div_3">
</div>
</div>
</div>
|
or if a link is given this:
Code: | <a href="mydomain.com">
<div class="div_1">
<div class="div_2">
<div class="div_3">
</div>
</div>
</div>
</a>
|
But the actual output is this:
Code: | <a href="mydomain.com"> </a>
<div class="div_1">
<a href="mydomain.com"> </a>
<div class="div_2">
<a href="mydomain.com"> </a>
<div class="div_3">
</div>
</div>
</div>
|
What am I missing here? Why is the anchor not wrapped around everything and comes up multiple times?
PS: I know that my code with that div disaster isn't the best, and also the classes. I just made this to demonstrate my code. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri May 21, 2021 1:51 pm Post subject: |
|
|
Unable to reproduce. Code: | <?php
require_once __DIR__ . '/smarty-config.php';
$smarty->assign([
'Data' => ['link' => 'xxx'],
]);
$smarty->display(__FILE__);
__halt_compiler()?>{capture name="capture_1"}
<div class="div_1">
<div class="div_2">
<div class="div_3">
</div>
</div>
</div>
{/capture}
{if $Data.link}
<a href="{$Data.link}">
{$smarty.capture.capture_1}
</a>
{else}
{$smarty.capture.capture_1}
{/if} |
Code: |
<a href="xxx">
<div class="div_1">
<div class="div_2">
<div class="div_3">
</div>
</div>
</div>
</a> |
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|