如何使用ejs模板在Sailsjs中设置元描述标签? [英] How can I set a meta description tag in Sailsjs using ejs templates?

查看:94
本文介绍了如何使用ejs模板在Sailsjs中设置元描述标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从sails控制器操作中设置description元标记.我搜索了所有内容,但是唯一的示例涉及页面标题.这是我的第一个node.js和sailsjs网站,这是我做错了吗? 像这样:

I would like to be able to set the description meta tag from the sails controller action. I have searched all over, but the only example involves the page title. This is my first node.js and sailsjs site, am I going about this the wrong way? Something like this:

module.exports = {
index: function (){
res.view(
  {
    title: 'The Title Text', 
    metaDescription: "The Description Text"
  });
  }
};

推荐答案

是的,这是正确的.您可以使用

Yes, this is correct. You can insert in your template with

<!DOCTYPE html>
<html>
  <head>
  <title><%= title %></title>
  <meta name="description" content="<%= metaDescription %>">

文档和示例可以在这里找到:

Docs and examples can be found here:

http://sailsjs.org/#!/documentation/concepts/Views/Locals.html http://sailsjs.org/#!/documentation/reference/res /res.view.html

这篇关于如何使用ejs模板在Sailsjs中设置元描述标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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