Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Capture not working as expected

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
jonal
Smarty Rookie


Joined: 16 Apr 2021
Posts: 11

PostPosted: Wed May 19, 2021 9:15 am    Post subject: Capture not working as expected Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri May 21, 2021 1:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP