|
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 |
joao.marmentini Smarty n00b
Joined: 15 Dec 2020 Posts: 1
|
Posted: Tue Dec 15, 2020 5:15 pm Post subject: AJAX and SMARTY |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Dec 16, 2020 8:25 pm Post subject: |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Dec 16, 2020 8:26 pm Post subject: Re: AJAX and SMARTY |
|
|
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 |
|
Codez Smarty Rookie
Joined: 23 Aug 2014 Posts: 7
|
|
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
|