如何设置不同的< title> ejs中每个模板的值? [英] How can I set different <title> values for each template in ejs?

查看:196
本文介绍了如何设置不同的< title> ejs中每个模板的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Sails.js,它带有ejs-templates。有一个名为layout.ejs的默认视图,该视图始终包含其他模板的主体部分。 title元素在layout.ejs中定义,因此始终相同。由于使用了SEO,我想根据所包含的视图来更改标题。是否可以通过某种方式知道.ejs文件中从Sails实际调用了哪个视图?

I am using Sails.js and it comes with ejs-templates. There is a default view called layout.ejs which is always including the body parts from other templates. The title element is defined in the layout.ejs and is therefore always the same. Due to SEO I would like to change the title depending on the view that is included. Is there some way of knowing which view is actually called from Sails, in the .ejs file?

推荐答案

更新<$ c您的 layout.ejs 的$ c>< title> 标记为

Update the <title> tag of your layout.ejs to

< title><%=标题%>< / title>

并发送<$ c来自控制器的$ c> title 值以及其他数据,例如

and send a title value from your controller along with the other data, like

res.view('viewname' ,{title:'YourTitle',data:data});

希望这会有所帮助!

这篇关于如何设置不同的&lt; title&gt; ejs中每个模板的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆