

Otherwise, it will just be regarded as plain text and not an HTML element. The span is declared on the next line after the bar (|). So, the static year is replaced with a span with id year. Okay, so just need to declare an element with id year. script.ĭocument.getElementById( 'year').textContent = new Date().getFullYear() With JavaScript, it will be easy to find an element and push the content inside it. Unfortunately, I could not able to find any straightforward way to directly use this currentYear variable with any HTML element. Now, we need to display it inside the footer where it is intended. If not present, then it will think of script as an HTML element.Īlright. Var currentYear = new Date().getFullYear() Let's understand how to include an inline JavaScript block inside the pug file. Upon searching on the internet I got some answers those talked about including inline JavaScript inside the pug file, however, they did not really talk about how to take one JavaScript variable and display it in the pug.

Now the challenge is to remove the static 2021 and replace it with the dynamic year from the JavaScript Date Object.

Here is the rendered HTML screenshot from the Chrome developer tool. At last, the two children would be a small Copyright text and an anchor. Copyright Sectionĭiv.copyright.py -4.text-center.text-whiteīasically, this pug code will generate a division with mentioned classes and then another container division inside it.
When I checked the code inside the index.pug, I saw this. In CodePen, whatever you write in the HTML editor is what goes within the tags in a basic HTML5 template.Now, the thing is, we just need to take this code and place it at the correct place inside the HTML file templated by the index.pug. ajax 243 Questions angular 367 Questions arrays 889 Questions axios 127 Questions css 1069 Questions discord.js 211 Questions dom 195 Questions dom-events 236 Questions ecmascript-6 206 Questions express 241 Questions firebase 219 Questions forms 130 Questions google-apps-script 168 Questions html 2372 Questions javascript 14168 Questions. Meaning, going forward, no need to modify the HTML again and again. However, it was static and I wanted to make it dynamic. In my blog, there is a footer where I am showing the current year. Let's discuss one of the problems that I faced with it and how I solved it. I was able to fairly understand and make changes. When I started, I saw an index.pug file inside the project that is driving the whole HTML. Otherwise the resulting sourcemap will have a broken offset.Recently, I started revamping my personal website and used an opensource template from Github - startbootstrap-freelancer. The JavaScript preprocessors should preserve the code whitelines of the original source code. Is specified in an external file -> ( async function main () )
