Videos
A template can have a wide range of meanings in the world of web development. It can mean anything from simple HTML markup that is used when rendering data to a full website built out in HTML, JavaScript, and CSS that you can adapt to your needs.
I think in your context, the person you are talking to is saying they will provide the CSS style sheets (that give you the look and feel of the website) as well as example HTML pages to show you how to utilize the various components. The Bootstrap framework is a good example of this type of template. Bootstrap itself is primarily just CSS and JavaScript, but they provide you with many examples of HTML so you can understand how to utilize the available components.
when someone tells me if they are providing css stylesheet / template is that the same thing?
When someone tells you something and you're unsure of what they're telling you, it's appropriate to ask them to clarify.
No one on Stack Overflow can answer with certainty some vague statement by some other unknown developer.
does the template only give me the the way my page looks and do I have to map html to the css to replicate site similar to that?
So lets back up a bit and discuss jargon.
In common web-developer parlance "stylesheets" refer to CSS stylesheets, and "templates" refer to example HTML structures that can be reused with different data.
An example widget template might look like
<div class="widget">
<div class="widget__header">Header of the widget</div>
<img class="widget__image" src="http://placehold.it/200x150"/>
<div class="widget__description">lorem ipsum dolor sit amet</div>
</div>
In this example, the HTML contents and attributes may be updated to show a widget with any sort of content that you'd like.
All that said: different tools/products/server-side languages have different jargon. One CMS I use calls the structured server-side code "templates" whereas another calls the data structures themselves "templates", so context is important.
This issue you are running into is a common one and several solutions have been developed to reduce redundancies. As you hinted at, they usually involve extracting shared logic into a separate, reusable (and optionally parameterized) template. Having a server do pre-processing on your HTML and including the relevant templates at the right spots would do the trick.
Alternatively, if you don't want to spin up a server just for this, you could use a frontend library (popular choices at the moment are React and Angular) that allows you to extract shared logic into reusable components.
If installing a frontend library for this purpose is also too much overhead, you could roll your own templates by extracting repetition into a function:
function template() {
document.getElementById("some-container-id").innerHTML='your html code here';
}
That template function could optionally take parameters which it could substitute inside the HTML string.
I should add a word of warning, however, as coding in strings is ugly and error prone, and you may run into common issues that frontend libraries have already solved. You can manually create HTML entities and assign them as relatives of each other, but arguably that's even more cumbersome than programming in strings.
There are two strategies you could use to solve your problem. They both come with their pros and cons, but they primarily depend upon one question: are you using a bundler or not?
Using an external HTML file as a template and injecting it into the page
One of the approaches could be to write a template file, requesting it via javascript and then injecting it into the DOM.
The problem with this method is that you have to set up / your server to have this useless static page available through a request, but then you could easily create subdirectories like /static/templates/navbar.html.
This is a short example of this approach:
fetch('/static/templates/navbar.html').then(response => {
if(response.ok)
return response.txt();
}).then(page => {
document.body.innerHTML += page;
});
The obvious limitations of this method are that you need to create an HTML template file for every component and load them in order, otherwise, your DOM will be a mess (1), and then you will need to download all these templates that will require additional bandwidth.
Refactoring your tags via javascript and injecting them into the page
In case you are using a bundler, I honestly think this approach is more sustainable as you are not requesting any other file, instead, you can create these elements via javascript and then load them via another script. The script will contain a function (something like init() or similar) that will inject the elements into the DOM.
const nav = document.createElement('nav');
const ul = document.createElement('ul');
ul.id = 'menu';
const li01 = document.createElement('li');
const a01 = document.createElement('a');
a01.href = 'watchlist.html';
a01.innerText = 'Watchlist';
li01.appendChild(a01);
ul.appendChild(li01);
nav.appendChild(ul);
And from here you can understand how it works. The good thing about this approach is that you don't need to request any external file and that you can write all this code inside another file that the bundler will automatically compile into a single .js (2). On the other hand, if your menu is huge your time to interactive might peak up due to all the javascript calculations.
Use a javascript framework
As already stated from another user, there are different frameworks that are being used that allow you to create templates called components and then load them dynamically, such as React, Preact, VueJS, Angular and many others. Learning at least one of these will absolutely help you in case you want to look for a job in web development. The downside of this approach is that you're basically injecting a lot of functions that you may never use into your code, which will obviously be slower compared to vanilla javascript.
Take your pick!
(1) remember that fetch is an asynchronous function, and therefore it doesn't load assets in order. (2) in case for some reason you don't want to use a bundler, you could still load the file via another script tag.