Z
Z
zekin3752020-11-11 14:49:10
1C-Bitrix
zekin375, 2020-11-11 14:49:10

How to pass product property to script.js?

Is there an array

<?
$group = 10
?>

How to pass this array to script.js file in catalog component

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2020-11-11
@anton99zel

<script type="text/javascript">
var GROUP = '<?php echo $group;?>';
document.write('Твоя переменная теперь в js ' + GROUP);
alert("Твоя переменная теперь в js " + GROUP + "!");
</script>

Y
Yaroslav Alexandrov, 2020-11-11
@alexyarik

/*Код в template.php*/
BX.ready(function () {
var ourJsObj = new ourJs(<?= json_encode($ourParams) ?>);
});
/*Код в script.js*/
ourJs = function (params) {
this.params = params;
console.log(this.params);
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question