|
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 |
homerun31 Smarty n00b
Joined: 14 Sep 2018 Posts: 1
|
Posted: Fri Sep 14, 2018 4:17 pm Post subject: Loop over variables from within a template |
|
|
Is there a way to loop over each variable that's available in a template, without knowing which variables were passed to the template?
I've tried $smarty->getTemplateVars() from within the template but nothing gets outputted.
To give some context, I was given a job where I only have access to the template files, and not really able to edit the backend code easily. I also don't have any access to the server that the code lives on, so updates to the template files can sometimes take a few days to be set live. If there is a major issue with one of the templates, its possible that a decent amount of time can go by before a fix is made. So I was thinking of having each template output all of the available variables in a big json object, and then building a frontend on a server that I have more control over and then using curl or ajax calls to get the data I need. Any ideas on how to accomplish this? |
|
Back to top |
|
bsmither Smarty Elite
Joined: 20 Dec 2011 Posts: 322 Location: West Coast
|
Posted: Fri Sep 14, 2018 6:11 pm Post subject: |
|
|
I have no experience at solving your specific approach.
My solution is to add {debug} to the end of the template I want to troubleshoot. See:
https://www.smarty.net/docs/en/language.function.debug.tpl
Once you can convince the server admins to add this to the instantiation of the Smarty class:
Code: | $smarty->debugging_ctrl = ($_SERVER['SERVER_NAME'] == 'localhost') ? 'URL' : 'NONE'; | where $_SERVER['SERVER_NAME'] == 'localhost' can be any kind of test (such as IP address, or a passcode in the querystring, etc), then you can get a debug console on demand. See:
https://www.smarty.net/docs/en/chapter.debugging.console.tpl |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Sep 14, 2018 9:26 pm Post subject: Re: Loop over variables from within a template |
|
|
homerun31 wrote: | To give some context, I was given a job where I only have access to the template files, and not really able to edit the backend code easily. I also don't have any access to the server that the code lives on, so updates to the template files can sometimes take a few days to be set live. If there is a major issue with one of the templates, its possible that a decent amount of time can go by before a fix is made. So I was thinking of having each template output all of the available variables in a big json object, and then building a frontend on a server that I have more control over and then using curl or ajax calls to get the data I need. Any ideas on how to accomplish this? |
You can use {debug} tag to see assigned variables, but…
Normally, this is accomplished by setting a development suite that you have full access to.
Smarty is not a self-contained application, you can't realistically separate it from the rest of the project. |
|
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
|