简体   繁体   English

术语“模板”是什么意思?

[英]What does the term “template” mean?

I am learning Rails 5.0, via a tutorial. 我正在通过教程学习Rails 5.0。 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. 我在Rails文档中进行了搜索,他们似乎提到了很多单词,但从未真正明确定义它。

I know that views are the HTML, CSS associated with what the user sees. 我知道视图是与用户看到的内容相关联的HTML和CSS。 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. RoR使您可以动态生成内容。 This means, with one template, you could generate different content (html pages). 这意味着,使用一个模板,您可以生成不同的内容(html页面)。 The final html page generated and served by the server is the webpage endusers see. 服务器生成并提供服务的最终html页面是最终用户看到的网页。 For example, you could have a template show.html.erb with the following line: 例如,您可以使用带有以下行的模板show.html.erb:

<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. 通过此模板,可以使用该@product的名称生成每个不同@product的不同网页,具体取决于控制器提供的@product变量。

So templates allow you to dynamically generate content and render them as different html webpages. 因此,模板允许您动态生成内容并将其呈现为不同的html网页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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