Answer the question
In order to leave comments, you need to log in
How to get variable from template in js?
Good day. If the script is connected directly in the template, it works fine.
function addLink(e) {
e.preventDefault();
var pagelink = ' <a href="' + document.location.href + '">{$_modx->resource.name | lower}</a> ';
бла бла и т.д.
{$_modx->resource.name | lower}
remains itself, instead of substituting the resource name in lower case. {$_modx->resource.name | lower}
work?
Answer the question
In order to leave comments, you need to log in
you can do something like this:
in the template
well, in js you get the value of the attribute
let resName = document.querySelector("[data-modx-resource-name]").dataset.modxResourceName;
console.log(resName);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question