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

Infinite Scroll With Smarty

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


Joined: 02 Sep 2016
Posts: 2

PostPosted: Mon Mar 13, 2017 3:41 am    Post subject: Infinite Scroll With Smarty Reply with quote

Hello,

I'm creating a blog service, and am using PHP with Smarty. I was wondering if it was possible to render a .tpl template from JavaScript?

I have a blogpost.tpl file which outlines what my blogpost looks like.

My code is as follows:
Code:

$(window).scroll(function(){
       // If the user has scrolled the height of the window, load more blog posts
       if($(window).scrollTop() == $(document).height() - $(window).height()){
          $('.ajax_loader_wrapper').css('display', 'block');

          const offset = $("#offset").val();
          $.ajax({
             type: "POST",
             url: 'controllers/get_entries.php',
             data: {
                offset: offset
             },
             success: function(posts){                
                $("#offset").val(offset + 3);

                                // Code to render additional blogposts, preferably from the existing template
                                // TODO
             }
          });
       }
    });


My question is regarding the "TODO" section above. Manually in JS, this logic would involve creating the HTML from scratch and appending it to the bottom, which seems redundant given that I already have a template file that outlines what the HTML would look like. I am also concerned about doing this locally because I have server-side logic in the template (such as checking to see if the user is logged in, and showing Edit/Delete buttons if they are), and this would be a security issue if done locally.

I would much prefer to do this over pagination. I am also set on making this on my own, as opposed to using an existing jQuery plugin.

Thanks in advance! Any advice would be appreciated.

Jake
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Mar 13, 2017 5:39 am    Post subject: Reply with quote

You have to request a page that returns new batch of elements to your JS.
How do you do that on server(PHP) side is irrelevant to client (JS) side.
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