admin管理员组文章数量:1400201
I have a combination of Google Apps Script logic and JavaScript that I am using within my Nunjucks environment. The logic looks like this within one of my views
//...Nunjucks logic above
<script>
//debug | see parameter data in terminal and on page
function displayParameterData() {
const datags = <?!= JSON.stringify(data) ?>;
console.log(datags);
document.write(JSON.stringify(datags));
}
displayParameterData();
</script>
//...Nunjucks logic below
When I build my npm project, Nunjucks makes the following adjustment to my datags value above...
< ? ! = JSON.stringify(data) ? > ;
Is there anyway I can tell Nunjucks to not make that adjustment and leave the markup exactly how it is in this specific area?
I found other resources on stack in regards to Nunjucks espcaping, but nothing close enough to the code setup of my situation..
Thanks for any advice
I have a combination of Google Apps Script logic and JavaScript that I am using within my Nunjucks environment. The logic looks like this within one of my views
//...Nunjucks logic above
<script>
//debug | see parameter data in terminal and on page
function displayParameterData() {
const datags = <?!= JSON.stringify(data) ?>;
console.log(datags);
document.write(JSON.stringify(datags));
}
displayParameterData();
</script>
//...Nunjucks logic below
When I build my npm project, Nunjucks makes the following adjustment to my datags value above...
< ? ! = JSON.stringify(data) ? > ;
Is there anyway I can tell Nunjucks to not make that adjustment and leave the markup exactly how it is in this specific area?
I found other resources on stack in regards to Nunjucks espcaping, but nothing close enough to the code setup of my situation..
Thanks for any advice
Share Improve this question edited Mar 25 at 21:59 Progman 19.7k7 gold badges55 silver badges82 bronze badges asked Mar 25 at 4:37 klewisklewis 8,41816 gold badges69 silver badges112 bronze badges2 Answers
Reset to default 0The issue you’re running into is that Nunjucks is escaping the < ? ! = ... ? >
syntax because it doesn’t recognize it as part of its templating system. Nunjucks provides a {% raw %}
block that prevents the templating engine from processing specific parts of your code
Try this out,
{% raw %}
<script>
//debug | see parameter data in terminal and on page
function displayParameterData() {
const datags = <?!= JSON.stringify(data) ?>;
console.log(datags);
document.write(JSON.stringify(datags));
}
displayParameterData();
</script>
{% endraw %}
After much testing, what worked for me was actually modifying my .pipe() process within my gulp-nunjucks-render settings, which is an npm package within my gulpfile.js file.
In detail, right before my Nunjucks .html files are sent to the /appsscript folder...
//DETERMINES IF WE ARE READY TO PREP AND PUSH TO GOOGLE
const GPREP = yargs.argv.gprep;
//...more code...
.pipe(gulpif(GPREP, dest(mApps)))
...I am now using two additional pipe processes to find and replace ("correct"), the Google Apps Script tags, using the npm packages gulp-replace...
.pipe(gulpif(GPREP, replace('< ? !','<?!')))
.pipe(gulpif(GPREP, replace('? > ;','?>;')))
.pipe(gulpif(GPREP, dest(mApps)))
As a result, when I look at my .html file in my /appsscript folder, the script is now corrected...
<script>
//debug | see parameter data in terminal and on page
function displayParameterData() {
const datags = <?!= JSON.stringify(data) ?>;
console.log(datags);
document.write(JSON.stringify(datags));
}
displayParameterData();
</script>
本文标签: javascriptStop Nunjunks from spacing out specific tagsStack Overflow
版权声明:本文标题:javascript - Stop Nunjunks from spacing out specific tags - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744217649a2595714.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论