প্রথমে এই Defination টা দেখে নেই ।
A template engine is simply a way to turn static documents into dynamic ones.
Assume we have a template like this:
Welcome Jeremy
This doesn't help much, but if we turned it into a dynamic template
Welcome {{name}}
We can tell the Backend to render any name we want. The backend could change the name based on input from a form, from the URL, from a cookie, anything really. So it makes the documents able to work with a wider range of inputs.
As for what a template language does.
Basically, you write templates out, then at run time (when the backend gets ready to send a document back to the browser), the backend "compiles" the templates. To do this it simply finds all the placeholders (e.g. {{name}}) and replaces them with a variable (or something else depending on the templating language). That's all. It's incredibly simple but very very useful.
এবার একটু ব্যাখ্যায় আসি।
Facebook এর কথায় ধরেন তাদের মিলিয়ন মিলিয়ন ইউজার । আমি বাংলাদেশী এখন Facebook-এ আমার একটা Account আছে। আর আমেরিকায় আমার এক বন্ধু নিউ ইউর্ক থাকে তার একটা Account আছে । এবার আমি যদি বাংলাদেশ থেকে লগিন করি তাহলে আমার প্রোফাইলে ডুকলে তো আমেরিকায় বসে থাকা আমার বন্ধুর প্রোফাইলের ইনফরমেশন দেখাবে? অবশ্যই না, আমার ইনফরমেশন দেখাবে।
এবার Facebook কি মিলিয়ন মিলিয়ন user এর জন্য মিলিয়ন মিলিয়ন আলাদা করে কোড লিখেছে ? অবশ্যই না, তারা Just একটা টেমপ্লেট বা ফরমেট লিখেছে। ইউজাররা শুধু তাদের নাম দিবে বাকিটা অটোমেটিক তৈরি হবে। নিচের টেমপ্লেট টা লক্ষ্য করুন
Welcome to {{name}}
Name যার নাম দিবেন তার ক্ষেত্রেই Welcome to (any_name) দেখাবে। এবার আমি যদি রহিম নামের একটা একাউন্ট বাংলাদেশ থেকে করি, তাহলে Welcome to রহিম দেখাবে, আর যদি আমার বন্ধু আমেরিকা থেকে John নামে একটা একাউন্ট ওপেন করে, তাহলে তার প্রোফাইলে Welcome to John দেখাবে। আর এই কাজটা একটা ইঞ্জিনের মাধ্যমে সম্পন্ন করা হয়। এটাকেই বলছি আমরা Template Engine
ExpressJs এ অনেক টেমপ্লেট ইঞ্জিন আছে । গুগল করেন তাহলে পেয়ে যাবেন।