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

Loop over variables from within a template

 
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
homerun31
Smarty n00b


Joined: 14 Sep 2018
Posts: 1

PostPosted: Fri Sep 14, 2018 4:17 pm    Post subject: Loop over variables from within a template Reply with quote

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
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Fri Sep 14, 2018 6:11 pm    Post subject: Reply with quote

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


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Sep 14, 2018 9:26 pm    Post subject: Re: Loop over variables from within a template Reply with quote

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
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