For example, there is such a code:

$(document).ready(function(){ var cur_width = $(window).width(); $(window).resize(function(){ if($(window).width() <= 720 && cur_width > 720){ //reload location.reload(); } else if($(window).width() > 720 && cur_width <= 720){ //reload location.reload(); } }); }); 

I want to put in tpl on smarty code. In which: in one condition I need a download like this: {block name = 'product_images_modal}} {include file =' catalog / 1.tpl '} {/ block}, in another: {block name =' product_images_modal '} {include file = 'catalog / 2.tpl'} {/ block}

How to do it?

    1 answer 1

    Use Ajax to dynamically load content. Your JS script runs on the client side, and the template is formed on the server side. So, in fact, what you want to do can be realized only by loading either the two templates at once (which is not good), or you can load the second template using the specified technology when the necessary events occur.

    ps if you use the jQuery framework, you can greatly simplify your life with its query generation capabilities: $ .Get () $ .Post $ .Ajax

    Pss
    I add an example of use with jQuery:
    Smarty

     {if $ParamPG eq 'm1'} {include file='catalog/1.tpl'} {elseif $ParamPG eq 'm2'} {include file='catalog/2.tpl'} {/if} 

    Php

     $ParamPG = (isset($_GET['ParamPG ']) ? $_GET['ParamPG '] : 'm1' ); 

    Js

     $(document).ready(function(){ var cur_width = $(window).width(); $(window).resize(function(){ if($(window).width() <= 720 && cur_width > 720){ $.get( "{!URL!}?ParamPG=m1", function( data ) {document.body.innerHTML= data}) } else if($(window).width() > 720 && cur_width <= 720){ $.get( "{!URL!}?ParamPG=m2", function( data ) {document.body.innerHTML= data}) } }); }); 
    • I don't know much about frameworks. I would understand how to load different templates under different conditions. The code has a page reload, not Ajax, but also a decent option. I want to make a very different version of the adapta. - Vladimir Rodichev 2:44 pm
    • Well, you don’t have a lot of options using different server templates, either Ajax or page reload. Without frameworks - see the first link. - Vladimir Klykov
    • Can you tell how to enter a template into a condition? - Vladimir Rodichev
    • I can, it is done on the side of php or smarty, but with JS you need to pass it as a request parameter. for ease of understanding. Now I will add a question. - Vladimir Klykov
    • Yes ... it is not easy. I thought it was made easier. - Vladimir Rodichev pm