javascript code with php into .tpl prestashop
NickName:nicogaldo Ask DateTime:2015-06-11T05:04:14

javascript code with php into .tpl prestashop

I'm trying to do a conditional selector with javascript and php. I have already done before, but in wordpress (pure php), now I have to adapt to prestashop (.tpl file).

It is not so easy to write php inside a .tpl, and updated the Smarty to SmartyBC class. But I is still complicated

/public_html/controllers/front/certificadosController.php

class certificadosControllerCore extends FrontController{

      public $php_self = 'certificados';

      public function init(){
         parent::init();
      }
      public function initContent(){
          parent::initContent();
          $this->setTemplate(_PS_THEME_DIR_.'certificados.tpl');
      }
} 

function ConectarBD() {
 // connect to db
}

function TraerProd() {    
//get all products 
}

function TraerAttr($vid_prod) {
 //get atributtes 
}

As is the logic? I'm using the labels {php} php code {/ php} {literal} js code {/ literal}

I show them a piece of my code where prestashop apparently not interpreted well.

/public_html/themes/theme/certificados.tpl

{literal}

var_attr = '<option value="default" selected>Diametro</option>';
sel_attr = $('#attr');

$('select').change(function() {
    switch(this.id) {

    case 'producto':

        sel_attr.find('option').remove();
        sel_attr.append(var_attr);
        sel_attr.show();
        sel_attr.removeAttr('disabled');

        if (this.value == 'Válvula_de_bloqueo_Pead' ) {
            for (i = 0; i < Válvula_de_bloqueo_Pead.length; i++) {
                    $("#attr").append(
                            '<option value="' + Válvula_de_bloqueo_Pead[i] + '">' + Válvula_de_bloqueo_Pead[i] + '</option>'
                    );
            }

        {/literal}
        {php}

$Prod=array(); 
$Prod=TraerProd();

if (!empty($Prod)) { 
    $cntProd=count($Prod); 
}; 

            for ($k = 0; $k < $cntProd; $k++) {

                $_prod = $Prod[$k]['name']; $_prod = str_replace(array(' ', '-', '"', '/', '.', 'ñ'), array('_', '_', '', '_', '_', 'n'), $_prod);

                $Attr=array();
                $id_prod=$Prod[$k]['ID'];
                $Attr=TraerAttr($id_prod);

                if (!empty($Attr)) {

                    echo '} else if (this.value =='.$_prod.') { for (i = 0; i <'.$_prod.'.length; i++) { $("#attr").append("    <option value="\'+'.$_prod.'[i]+\'">\'+'.$_prod.'[i]+\'</option>");}';

                }
            } /* cierre if, for (php) */ 

        {/php}
        {literal}

        } //cierre if (js)
    break;
}

Seeing the results chain shows me the cut, I think that's excessive use of the labels {php} and {literal}

This is the JSFiddle to have an idea of what I want to accomplish, I repeat, as I have in wp, but .tpl file complicates me all :(

I hope you can help me, sorry for my bad English. Thanks!

Copyright Notice:Content Author:「nicogaldo」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30767274/javascript-code-with-php-into-tpl-prestashop

More about “javascript code with php into .tpl prestashop” related questions

javascript code with php into .tpl prestashop

I'm trying to do a conditional selector with javascript and php. I have already done before, but in wordpress (pure php), now I have to adapt to prestashop (.tpl file). It is not so easy to write ...

Show Detail

Prestashop PHP Include in a .tpl does not work

I am creating a storefront for a client using Prestashop. Prestashop uses Smarty .TPL files. I read through smarty documentation and scoured the web but all of the suggestions are not working. I f...

Show Detail

How to inspect html code in Prestashop to link to the PHP TPL files

It is my understanding (prob completely wrong) that the php/tpl/etc files of a Prestashop site create the html page(s) of my website (see image). Im using Developer tools on Firefox Quantum Dev ed...

Show Detail

how to add php code in .tpl file in prestashop

Does anyone know how to add php code in .tpl file in prestashop..i tried a lot but couldn't find any solutions..I want to add a mail function in my .tpl file This is the function &lt;?php $na...

Show Detail

PHP Prestashop extend form.tpl

I would like to extend the form.tpl of Prestashop (1.6.1.1). Therefor I created the following path in my module folder: modules/mymodule/views/templates/admin/export/helpers/form/form.tpl and

Show Detail

How to detect device in smarty in prestashop 1.7 in a TPL file?

I want the following: &amp; I understand I have to take the codes from context.php of PrestaShop but I seem to be making an error. A link to getcontext is as follows: (The code to detect mobile de...

Show Detail

Display content with display.php and display.tpl in PrestaShop

I read http://doc.prestashop.com/display/PS16/Displaying+content+on+the+front+office and I try to create a display.php file and a display.tpl file. But I don't realize for sure where they must be ...

Show Detail

Prestashop and smarty php code

I want to include in prestashop (smarty) in the folder "/themes/my_template/modules/my_modul" a php file in the tpl. example: &lt;?php include('/tools/smarty/Smarty.class.php'); $smarty = new

Show Detail

Error TPL PHP Prestashop

I am working on Prestashop and I would like to retrieve the data from a table I created in my database. I've been on it for 2 days and nothing works, I'll go crazy. Here is the code I put in my

Show Detail

prestashop 1.7.5 show product-discounts.tpl into miniatures/product.tpl

i have problems when i try to show product discounts into the miniatures of search results. I'm using prestashop 1.7.5.1 version and php 7.0 in templates/catalog/product.tpl y have the followin co...

Show Detail