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

Odd problem with Smarty template - Get data from server.

 
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
gordonisnz
Smarty Regular


Joined: 05 Sep 2009
Posts: 70

PostPosted: Fri Jul 20, 2018 11:07 am    Post subject: Odd problem with Smarty template - Get data from server. Reply with quote

Hello. Im developing a website where I have a google map.

What i have so far (working).

I have a google map with various icons. If I click on an icon, it sends data to a PHP script.

- the php script accesses a database & extracts more data.
- this data is in the form of an array & i CAN use PHP "echo" to display the information inside a 2nd DIV in my template.

This is going ok & i am able to display what i want.

PROBLEM: The data / output is created within the PHP script & not via the usual Smarty template.

QUESTION: Is there a way using the Smarty template, that I can activate the PHP via clicking on the Google map icon - & create a new array.

Then re-load / refresh JUST the specified DIV but replacing Smarty with the new array data ?

I can do this by refreshing the WHOLE page, but the way it is now, I only refresh the div with new information. The rest of the page does not refresh.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Jul 20, 2018 11:25 am    Post subject: Reply with quote

http://php.net/json_encode

You do't need Smarty to send AJAX reply.
Back to top
View user's profile Send private message
gordonisnz
Smarty Regular


Joined: 05 Sep 2009
Posts: 70

PostPosted: Fri Jul 20, 2018 11:35 am    Post subject: Reply with quote

AnrDaemon wrote:
http://php.net/json_encode

You do't need Smarty to send AJAX reply.


Sending / Requesting the Ajax query is OK. The problem is - How do i REPLACE the results in my template with the new data ?


If my div has $array.name and it has "jones".

i press a button & it activates the script - the new value is "Peter". How do i refresh the DIV to load the NEW data.

DIV 1 - Press button. It reloads/refreshes the data in DIV2.

(the rest of the page DOES NOT refresh).

DIV2 shows the results.

IF i want to edit the presentation/display of the results now - I have to go to the PHP script & find the echo commands & change the presentation there. I cant simply edit the Smarty template to change the layout.
Back to top
View user's profile Send private message
gordonisnz
Smarty Regular


Joined: 05 Sep 2009
Posts: 70

PostPosted: Fri Jul 20, 2018 12:16 pm    Post subject: Reply with quote

After much research / googling - Ive found the answer.

When using a 2nd template, it does not automatically use the same SMARTY class as the main script.

Ive added these lines to the end of my 2nd / mini PHP script:

Code:

require_once ('PATH/usr/smarty3/libs/Smarty.class.php');
require_once ('../includes/Templates.inc.php');

   $template_data['directory_data']=$data;
    Process_Template ("directory/directory_data.tpl",$template_data);


(ive got a 'directory' subdirectory under my usual Smarty template path)
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Jul 21, 2018 2:08 am    Post subject: Reply with quote

Why are you not using autoloading?…
Back to top
View user's profile Send private message
gordonisnz
Smarty Regular


Joined: 05 Sep 2009
Posts: 70

PostPosted: Sat Jul 21, 2018 3:04 am    Post subject: Reply with quote

AnrDaemon wrote:
Why are you not using autoloading?…


I havent heard of that before now..

- So far ive only edited / changed smarty templates. Ive not altered the main Smarty class or added any new functions.

(found a few forums on autoloading & it appears its some additional class or something for PHP Smarty).


Though this thing i needed it for is probably a one-off thing, I'll not need it for anything else (I think). but my technique above does work...
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Jul 21, 2018 10:00 am    Post subject: Reply with quote

http://getcomposer.org/
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