简体   繁体   中英

What does the term “template” mean?

I am learning Rails 5.0, via a tutorial. Learning how to generate view templates, but the term "template" is never explicitly defined. I've searched in the Rails docs, and they seem to mention the word a lot, but also never really define it explicitly.

I know that views are the HTML, CSS associated with what the user sees. But was wondering what is a template and how is it different than a standard webpage?

I don't have an authoritative answer. But this is really rather simple. RoR lets you generate content dynamically. This means, with one template, you could generate different content (html pages). The final html page generated and served by the server is the webpage endusers see. For example, you could have a template show.html.erb with the following line:

<h> Product <%=@product.name%> </h>

From this template, different webpages for each different @product can be generated with that @product's name, depending on the @product variable, which is provided by the controller.

So templates allow you to dynamically generate content and render them as different html webpages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM