|
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 |
jbyman Smarty n00b
Joined: 02 Sep 2016 Posts: 2
|
Posted: Mon Mar 13, 2017 3:41 am Post subject: Infinite Scroll With Smarty |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Mar 13, 2017 5:39 am Post subject: |
|
|
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 |
|
|
|
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
|