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

AJAX and 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
joao.marmentini
Smarty n00b


Joined: 15 Dec 2020
Posts: 1

PostPosted: Tue Dec 15, 2020 5:15 pm    Post subject: AJAX and SMARTY Reply with quote

I'm new to smaty, but neverless i'm trying to develop a product slider in my shop. My issue is the mobile. I need to get a specific value when the user is on a phone (for example: 1) and another when he is on desktop (lets assume 2). I've been trying to get the document width with AJAX and send it to a tpl, but it doesnt seem to work. Where is the code:

AJAX:
$.ajax({
url: 'modules/bia_releasedproducts/views/templates/hook/bia_releasedproducts.tpl',
type: 'post',
data: {
width: $(window).width(),
height: $(window).height()
}
})
.done(function (response) {
alert(response);
})
.fail(function (error) {
alert(error);
})
.always(function () {
console.log("complete");
});
;

and my .tpl:

{foreach from=$products item="product" name=products_slider}
{if $smarty.foreach.products_slider.index mod $smarty.post.width mod 600 == 0}
<li>
{/if}
{include file="catalog/_partials/miniatures/bia_product.tpl" product=$product}
{if ($smarty.foreach.products_slider.index + 1) mod $smarty.post.width mod 600 == 0}
</li>
{/if}
{/foreach}
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Dec 16, 2020 8:25 pm    Post subject: Reply with quote

Consider the fact that PHP(Smarty) and JavaScript never run at the same time.

Also, see https://www.php.net/json_encode
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Dec 16, 2020 8:26 pm    Post subject: Re: AJAX and SMARTY Reply with quote

joao.marmentini wrote:
url: 'modu

Missing full path, host and likely protocol.

But host and full path are the least of the requirements.
Back to top
View user's profile Send private message
Codez
Smarty Rookie


Joined: 23 Aug 2014
Posts: 7

PostPosted: Sun Dec 27, 2020 11:59 pm    Post subject: Reply with quote

you need to post to a PHP file and then load the tpl file from there.

https://www.w3docs.com/snippets/php/how-to-create-a-jquery-ajax-post-with-php.html

to learn more
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