Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Passing variables to child loaded with ajax content

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
n2fole00
Smarty Rookie


Joined: 09 Jun 2020
Posts: 6

PostPosted: Mon Jul 06, 2020 12:26 pm    Post subject: Passing variables to child loaded with ajax content Reply with quote

Hi, If I have a template and inside that template I have a child template whose content is called via an ajax request, is it possible to pass down (or make available) variables from the parent template to the child template, taking into consideration this is dynamically loaded?

Thanks.
Back to top
View user's profile Send private message
bsmither
Smarty Elite


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

PostPosted: Tue Jul 07, 2020 1:48 am    Post subject: Reply with quote

I would think this "inheritance" or "passing along" data that populated one template - Smarty performs this population of the template on the server - to be available on a child template, can happen, as long as the child template is also having that data populate that child template at the same time on the server.

Knowing that AJAX calls are performed by the web browser, and this fetching is at a separate point in time, it then leads me to conclude that processing the AJAX request will need to have some code on the server perform the necessary data gathering and processing for that response.

That code could be gathering and processing the same data to populate a 'child/dynamic' area of the page (including having Smarty create an HTML snippet using a template) as was done to populate the 'parent' area of the page.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1646

PostPosted: Thu Jul 16, 2020 12:50 am    Post subject: Reply with quote

Correct. AJAX request happens when Smarty is long since dead, not to mention - it happens outside the server to begin with. Use client scripting to deal with data received from AJAX request.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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