Re: variable spip et javascript

JLuc <[email protected]> Tue, 4 May 2021 20:31:19 +0200
Newsgroups gmane.comp.web.spip.user
Message-ID <[email protected]>
Le 04/05/2021 à 18:46, jo.baloo a écrit :
> 1- est-il possible, au chargement, d'initialiser un tableau javascript par un tableau spip #GET{mon_tableau} ?
> si oui comment ?
> 2- si non est-il possible d'initialiser ce tableau javascript par une BOUCLE spip

Un code source javascript est un texte
que SPIP peut altérer ou entièrement générer
tout comme html (ou json, ou xml, ou yaml, ou css).

Par exemple dans un squelette html où tu as besoin de ce tableau js,
avec le code :

<script type="text/javascript">
var lesPoints = [];

<BOUCLE_remplitableaujs(ARTICLES){inverse}{recherche ?}{id_rubrique?}>
	lesPoints.push({
		'id_article': #ID_ARTICLE,
		'titre': '#TITRE'
	});
</BOUCLE_remplitableaujs>

console.log(lesPoints);

</script>

Et si tu as déjà ton tableau SPIP, tu peux créer une fonction qui génère le source js
et ensuite faire simplement :
<script type="text/javascript">
lesPoints = [(#GET{mon_tableau}|array_to_js)];
</script>

JL