cocof Posted February 13, 2017 Posted February 13, 2017 (edited) Pour insérer du JS dans un template de PS 1.7, est-ce que l'ajout de {literal} suffit? <script type="text/javascript"> {literal} (function () { var headertext = []; var headers = document.querySelectorAll("thead"); var tablebody = document.querySelectorAll("tbody"); for(var i = 0; i < headers.length; i++) { headertext[i]=[]; for (var j = 0, headrow; headrow = headers[i].rows[0].cells[j]; j++) { var current = headrow; headertext[i].push(current.textContent.replace(/\r?\n|\r/,"")); } } if (headers.length > 0) { for (var h = 0, tbody; tbody = tablebody[h]; h++) { for (var i = 0, row; row = tbody.rows[i]; i++) { for (var j = 0, col; col = row.cells[j]; j++) { col.setAttribute("data-th", headertext[h][j]); } } } } } ()); {/literal} </script> Edited February 13, 2017 by cocof (see edit history) Share this post Link to post Share on other sites More sharing options...
cocof Posted February 13, 2017 Posted February 13, 2017 *Parce que ça ne marche pas chez moi... Share this post Link to post Share on other sites More sharing options...
koogar Posted May 15, 2019 Posted May 15, 2019 En effet sur le 1.6 et 1.7 ca ne fonctionne pas, aucun soucis sur les versions antérieurs a 1.6 Share this post Link to post Share on other sites More sharing options...
Esh-Network Posted May 15, 2019 Posted May 15, 2019 Bonjour, essaie comme ça : Quote {literal} <script type="text/javascript"> (function () { var headertext = []; var headers = document.querySelectorAll("thead"); var tablebody = document.querySelectorAll("tbody"); for(var i = 0; i < headers.length; i++) { headertext[i]=[]; for (var j = 0, headrow; headrow = headers[i].rows[0].cells[j]; j++) { var current = headrow; headertext[i].push(current.textContent.replace(/\r?\n|\r/,"")); } } if (headers.length > 0) { for (var h = 0, tbody; tbody = tablebody[h]; h++) { for (var i = 0, row; row = tbody.rows[i]; i++) { for (var j = 0, col; col = row.cells[j]; j++) { col.setAttribute("data-th", headertext[h][j]); } } } } } ()); </script> {/literal} Share this post Link to post Share on other sites More sharing options...
Mediacom87 Posted May 15, 2019 Posted May 15, 2019 il y a 34 minutes, koogar a dit : En effet sur le 1.6 et 1.7 ca ne fonctionne pas, aucun soucis sur les versions antérieurs a 1.6 Ah bon, pourquoi ? car j'utilise très souvent et cela marche très bien. Mais bon, je préfère utiliser les balises smarty {ldelim} et {rdelim} à la place des accolades. https://www.smarty.net/docsv2/fr/language.function.ldelim.tpl Share this post Link to post Share on other sites More sharing options...
koogar Posted May 15, 2019 Posted May 15, 2019 Je suis en train de modifier des footers, et je te promet que sur les 1.6 ca ne fonctionne pas, la page s'affiche mais le JS n'est pas interprété. Je vais essayer avec les balises smarty {ldelim} et {rdelim} à la place des accolades et je re @demain Share this post Link to post Share on other sites More sharing options...
Mediacom87 Posted May 16, 2019 Posted May 16, 2019 Si tu le dit, perso sur mon site j'ai les 2 écritures dans le header ou dans le footer et pas le moindre soucis de traitement. Je précise que hje suis bien en 1.6. Pour la 1.7 le soucis vient d’ailleurs mais logiquement avec du js pur cela devrait passer. Share this post Link to post Share on other sites More sharing options...
koogar Posted May 16, 2019 Posted May 16, 2019 Testé a l'instant sur la 1.6.1.4 Dans le footer.tpl La date ne s'affiche pas : <script type="text/javascript"> {ldelim} document.write(new Date().getFullYear());{rdelim}</script> <script type="text/javascript"> {literal} document.write(new Date().getFullYear());{/literal} </script> Sur la 1.5 aucun souci Share this post Link to post Share on other sites More sharing options...
Mediacom87 Posted May 16, 2019 Posted May 16, 2019 Dans un premier temps, savez vous pourquoi on utilise literal ou ldelim ? Car dans votre code cela ne sert à rien. Si je colle ce code : <script type="text/javascript">document.write(new Date().getFullYear());</script> <script type="text/javascript">document.write(new Date().getFullYear());</script> Dans mon PS 1.6.1.22 j'obtiens bien le résultat Share this post Link to post Share on other sites More sharing options...
koogar Posted May 16, 2019 Posted May 16, 2019 (edited) 1° Pour la 1.6.1.4 Tout en bas dans le footer: http://import.nc/ le code : <div class="text-center">2015 - <script type="text/javascript">document.write(new Date().getFullYear());</script> <a href="https://phpsources.net/" ><b>PHP SOURCES</b> Si on regarde le source de la page en ligne, le JS a disparu 2° Voir le footer, ici ca fonctionne avec balise, c'est une version 1.5.4 http://grossiste.nc/ 3° Je viens de le mettre a l'instant sur la 1.7, sans aucune balise, et comme tu l'as indiquer ca fonctionne : http://hempline.fr/ Edited May 16, 2019 by koogar (see edit history) Share this post Link to post Share on other sites More sharing options...
Mediacom87 Posted May 16, 2019 Posted May 16, 2019 Share this post Link to post Share on other sites More sharing options...
Mediacom87 Posted May 16, 2019 Posted May 16, 2019 essayez ce ci : {dateFormat date=$smarty.now|date_format:'%Y' full=0} Share this post Link to post Share on other sites More sharing options...
koogar Posted May 16, 2019 Posted May 16, 2019 O temps pour moi, je n'avais pas vu qu'il s’était glissé dans le coin a gauche, mais alors pourquoi le JS va s’interpréter en dehors du div... mystère pour moi. so, merci pour ton aide {dateFormat date=$smarty.now|date_format:'%Y' full=0} donne une erreur 500 Share this post Link to post Share on other sites More sharing options...
doekia Posted May 16, 2019 Posted May 16, 2019 heu document.write() ? On est plus dans les années 70 les gars un document.write dans un js qui va être maltraité par le chargement asynchrone et la compression ccc je sais pas ce que ça va donner mais surement rien de très bon au final Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now