Answer the question
In order to leave comments, you need to log in
How to correctly pass {{ var }} OctoberCMS to javascript?
Replace in given js (active hours), var today = new Date(); values from {{ var }} ?
Something like:
{% set date = "now"|date("H:i:s d.m.Y") %}
{% set hour = date|date("H") %}
{% set min = date|date("i") %}
{% set sec = date|date("s") %}
<script>
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
m = checkTime(m);
s = checkTime(s);
document.getElementById('txt').innerHTML =
h + ":" + m + ":" + s;
var t = setTimeout(startTime, 500);
}
function checkTime(i) {
if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
return i;
}
startTime();
</script>
var h = '{{ hour }}'
var m = '{{ min }}'
var s = '{{ sec }}'
Answer the question
In order to leave comments, you need to log in
Bring it to hidden inputs and pull in the script by IDs. If the script is directly in the template, output it there.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question