Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture append as item in associative array #538

Closed
vbezruchkin opened this issue Apr 22, 2019 · 2 comments
Closed

Capture append as item in associative array #538

vbezruchkin opened this issue Apr 22, 2019 · 2 comments

Comments

@vbezruchkin
Copy link

vbezruchkin commented Apr 22, 2019

Hello,

This task is very close to #366. But the previous solution does not fit the idea.

Let me explain in details.

I have one array and it's available in Smarty:
$arr = array('first' => 'One', 'second' => 'Two');

I want to extend this array with more items using capture:

{capture name='third' append='arr'}
Three
{/capture}

{capture name='fourth' append='arr'}
Four
{/capture}

As a result I would like to have array like this:
$arr = array('first' => 'One', 'second' => 'Two', 'third' => 'Three', 'fourth' => 'Four');

At the moment, capture does not allow to do this, as it does not pass any keys to the array during append. I know I can use $smarty.capture.third, etc. anyhow it's not the option for me right now.

Let me know if we can hack somehow the system, to get the results we expect.

Thanks

@vbezruchkin
Copy link
Author

I managed to achieve this, I modified Smarty_Internal_Runtime_Capture class.

and changed append in close to this one:

$_template->append($append, array($buffer => ob_get_contents()), true);

Not sure if this might be needed by anyone else :) I guess no. Please close the ticket if you find this irrelevant and useless.

Thanks

@wisskid
Copy link
Contributor

wisskid commented Feb 7, 2021

Hi @vbezruchkin. I'm closing this, no one else seems to find this useful. Sorry!

@wisskid wisskid closed this as completed Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants