Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
<meta name="title" content="${currentPage.properties['jcr:title']}">
<meta name="description" content="${currentPage.properties['jcr:description']}">
as my page doesnt have any description its coming with no value, however for meta tag for title is getting rendered same as title of my page.
Thanks!
Not sure what you are actually looking for. Please describe more about your issue and where you want to place it.
Generally, for page title and description,
<sly data-sly-use.page="com.adobe.cq.wcm.core.components.models.Page"/>
<div>Page Title: ${page.title}</div>
<div>Page Description: ${page.description}</div>
If you want to use in component
<div>Title: ${currentPage.title}</div>
<div>Description: ${currentPage.description}</div>
In Slightly, you can use the data-sly-attribute
block to include dynamic values for HTML attributes, including the title
and description
meta tags. Here's an example of how to include the title
and description
meta tags in your template:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title data-sly-attribute="title" content="${properties.metaTitle @ context='html'}">${properties.jcr:title @ context='html'}</title>
<meta name="description" data-sly-attribute="description" content="${properties.metaDescription @ context='html'}"/>
</head>
<body>
<h1>${properties.jcr:title}</h1>
<p>${properties.text}</p>
</body>
</html>
In this example, the title
tag includes the dynamic title
attribute using the data-sly-attribute
block. The content
attribute is set to the value of the metaTitle
property, using the @context='html'
attribute to sanitize the value. If the metaTitle
property is not set, the value of the jcr:title
property is used instead.
Similarly, the description
meta tag includes the dynamic description
attribute, with the content
attribute set to the value of the metaDescription
property.
Hello @Lokeshmullaguri
<meta name="title" content="${properties.metaTitle @content='html'}" >
<meta name="description" content="${properties.metaDescription @content='html'}" >
Please note, on your template you have 2 fields by the name "metaTitle" and "metaDescription" for the above code to work.
regards,
Preetpal
Hi,
<meta name="title" content="${currentPage.properties['jcr:title']}">
<meta name="description" content="${currentPage.properties['jcr:description']}">
as my page doesnt have any description its coming with no value, however for meta tag for title is getting rendered same as title of my page.
Thanks!
Views
Likes
Replies
Views
Likes
Replies