Reputation: 61
I want to add meta-key and meta-description fields to the page setting dialog, and then render them to the page. I was able to find that one can do something like this in the page template (html) file:
{% extends data.outerLayout %}
{% block extraHead %}
<meta name="description" content="this is the page description" />
{% endblock %}
But how do I allow the end user to insert these values?
Upvotes: 3
Views: 636
Reputation: 166
here is an improved way to do it:
{% block extraHead %}
<meta name="description" content="{{ data.page.metaDescription | truncate(146, true, "..") | safe }}" />
{% endblock %}
See the screenshot to illustrate the last point:
Upvotes: 0
Reputation: 61
Ok, so after looking in the apostrophe-sandbox demo site I was able to discover the answer.
I added under the lib/modules
folder in my project a new folder called apostrophe-custom-pages
, and inside that I added an index.js
file that looks like this:
module.exports = {
beforeConstruct: function(self, options) {
options.addFields = [
{
name: 'metaDescription',
label: 'Meta Description',
type: 'string'
},
{
name: 'metaTags',
label: 'Meta Tags',
type: 'string'
}
]
}
};
Then, inside my page html template I added:
{% block extraHead %}
<meta name="description" content="{{ data.page.metaDescription}}" />
<meta name="tags" content="{{ data.page.metaTags}}" />
{% endblock %}
That's it. It works. Now I can provide SEO support. Hurray! :)
Upvotes: 3