Smarty is a PHP templating engine, that is, it helps you generate HTML quickly and dynamically as in the case of your example, where Smarty is generating a select form
dynamically.
To do the same thing with Javascript or Jquery there are several ways.
Pulling from an object, which can be a JSON generated with PHP, using Javascript only:
var options = '',
//essa é a lista de onde sairão os valores das opções do select
movie_list = {
'The Revenant' : 'The Revenant',
'Deadpool' : 'Deadpool',
'Fight Club' : 'Fight Club',
"Birdman" : 'Birdman',
'Dallas Buyer\'s Club': 'Dallas Buyer\'s Club'
};
//itera pela lista pra gerar as opções do select
for(var key in movie_list) {
options += '<option value="' + key + '">' + movie_list[key] + '</option>'
}
//inclui as opções no select de id movies
document.getElementById('movies').innerHTML = options;
<select id="movies"></select>
JSFIDDLE
Pulling from an object, which can be a JSON generated with PHP, using Jquery:
var options = '',
movie_list = {
'The Revenant' : 'The Revenant',
'Deadpool' : 'Deadpool',
'Fight Club' : 'Fight Club',
"Birdman" : 'Birdman',
'Dallas Buyer\'s Club': 'Dallas Buyer\'s Club'
};
for(var val in movie_list) {
$('<option />', {value: val, text: movie_list[val]}).appendTo($('#movies'));
}
<select id="movies"></select>
JSFIDDLE 2
There are many more possibilities, it depends a lot on what you want to do and how you want to do it.
SENSATIONAL... with the examples already in codes it is easy for us to understand! I’ll be able to study that now.. Thank you very much!
– Roberval Sena 山本
No problem! Good luck in your studies!!!
– StillBuggin
Now.. moving on.. I have one more question, for example on this page .. this SMARTY code, working with an object ( with the name "$item_push"). further down in the part of < scripts > am putting this java code (which you gave as example...) however with the object "$item_push"... but the error... Then the question would be... how to use the "$item_push" object in the java part? or .... how do I know if I can use the same object that was in SMARTY, la in the part of < scripts > ? with JS ??
– Roberval Sena 山本
The answer is, you can’t! Javascript is used to manipulate the Document Object Model (DOM), creating, changing behavior, passing new attributes, modifying existing attributes, etc., acting on the front end (client side or client side). PHP (Smarty) acts together with HTML, but acts on the back end (server side or llado server), so you can use Smarty to generate a list and capture that list with Javascript to generate select.
– StillBuggin
Here are some examples of the Smarty forum: http://www.smarty.net/forums/viewtopic.php?p=87452&sid=bbb70837243b574dc88c07f38d9fed81
– StillBuggin
got it! and already adapted my need! thanks, including the extra links!
– Roberval Sena 山本