Assigning custom function
I've been reading and trying different methods but I haven't been able to assign variables from a custom tag. Something like: {8ball var1='num' assign='result'} {$result}
I saw that I could use a custom tag inside the assign tag, like this: {assign var="returndata" value={8ball var1='num'}} but that doesn't work with arrays as the return for the custom tag.
Is there any way to achieve this? Thanks for the help
Use {capture}{/capture}?
Probably won't work with arrays either.
Although this doesn't address the question directly, assigning variables in-template is an anti-pattern. You should be assigning variables from the PHP code to the template. This may require some refactor, but it will make things a lot easier and cleaner template-side.
On Tue, Oct 1, 2024 at 10:59 AM Simon Wisselink @.***> wrote:
Probably won't work with arrays either.
— Reply to this email directly, view it on GitHub https://github.com/smarty-php/smarty/issues/1068#issuecomment-2386400412, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHZCLHUXZC4B3OIXHTZJQLZZLBG5AVCNFSM6AAAAABPFSW46SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOBWGQYDANBRGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>
I've tried to use this: https://www.smarty.net/docs/en/plugins.functions.tpl
and set the output with the template assign function, it works and I managed to use the the variable on the template, the downside is that I get a lot of files on the template compile folder:
Any ideas on how to avoid creating so many compiled files? The site is quite big and has a lot of traffic, using this would mean the server would go out of free inodes in just some days.
Is there any way you can do this work in the PHP app and assign the variables to the template? Using a plugin function is handling business logic in the template, something you should do in the app.
On Wed, Oct 2, 2024 at 7:46 AM Damian Alarcon @.***> wrote:
I've tried to use this: https://www.smarty.net/docs/en/plugins.functions.tpl
and set the output with the template assign function, it works and I managed to use the the variable on the template, the downside is that I get a lot of files on the template compile folder: Screenshot.2024-10-02.at.9.43.39.AM.png (view on web) https://github.com/user-attachments/assets/d253bfc5-b44d-4c5d-bf09-dd9c15b91f4e Any ideas on how to avoid creating so many compiled files? The site is quite big and has a lot of traffic, using this would mean the server would go out of free inodes in just some days.
— Reply to this email directly, view it on GitHub https://github.com/smarty-php/smarty/issues/1068#issuecomment-2388559019, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHZCLFXY5JEQTI7MUAEMRDZZPTIXAVCNFSM6AAAAABPFSW46SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOBYGU2TSMBRHE . You are receiving this because you commented.Message ID: @.***>
it's a big site with an old version of Smarty (3.x) and I'm trying to update it to 5. I have no chance of changing the whole design of the site in the amount of time I got, there are functions starting a {include} in case some conditions have been met and a lot of subdivision on each one of the pages, it would take ages to move everything into php.
I see so this is a migration and you are stuck with what you've got. Can you show how it worked in Smarty 3 and what isn't working in Smarty 5? Is it just the additional compiled files?
On Wed, Oct 2, 2024 at 8:56 AM Damian Alarcon @.***> wrote:
it's a big site with an old version of Smarty (3.x) and I'm trying to update it to 5. I have no chance of changing the whole design of the site in the amount of time I got, there are functions starting a {include} in case some conditions have been met and a lot of subdivision on each one of the pages, it would take ages to move everything into php.
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
It's just a lot of those {insert} tags, but I see they are now deprecated
{insert} was deprecated in smarty 3.1, it would be best to move away from them. you can make things not cached other ways.
On Wed, Oct 2, 2024 at 10:53 AM Damian Alarcon @.***> wrote:
It's just a lot of those {insert} tags, but I see they are now deprecated
— Reply to this email directly, view it on GitHub https://github.com/smarty-php/smarty/issues/1068#issuecomment-2389029511, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHZCLHQJI7JQODEHSHFJDLZZQJIHAVCNFSM6AAAAABPFSW46SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOBZGAZDSNJRGE . You are receiving this because you commented.Message ID: @.***>
Since it's already documented, I hope someone knows how to use this: https://www.smarty.net/docs/en/plugins.functions.tpl without generating an external compiled file for the string and add it to the tpl compiled file instead