[opencms-dev] SEO description/keywords in meta-tags in detailpage

Andreas Gily andreas.gily at cardsys.at
Wed May 15 15:22:18 CEST 2013


Hi Sandrine,

Thanks for the tip:

For testing purposes I solved it via JSP Scriptlet - maybe I will create a custom tag later on:

<%@ page import="org.opencms.file.*" %>
<%@ page import="org.opencms.flex.CmsFlexController" %>  
<%@ page import="org.opencms.jsp.util.CmsJspStandardContextBean" %>
<%@ page import="org.opencms.util.CmsStringUtil" %>
<%@ page import="org.opencms.xml.content.CmsXmlContent" %>
<%@ page import="org.opencms.xml.content.CmsXmlContentFactory" %>
<%@ page import="org.opencms.main.CmsException" %>

<%
	CmsFlexController controller = CmsFlexController.getController(request);
        CmsObject cms = controller.getCmsObject();
        String result = null;
        
        try {
            CmsJspStandardContextBean contextBean = CmsJspStandardContextBean.getInstance(request);
            if (contextBean.isDetailRequest()) {
                // this is a request to a detail page
                CmsResource res = contextBean.getDetailContent();
                CmsXmlContent content = CmsXmlContentFactory.unmarshal(cms, res, request);
                //result = content.getHandler().getTitleMapping(cms, content, cms.getRequestContext().getLocale());
                if (result == null) {
                    // title not found, maybe no mapping OR not available in the current locale
                    // read the title of the detail resource as fall back (may contain mapping from another locale)
                    result = cms.readPropertyObject(res, CmsPropertyDefinition.PROPERTY_DESCRIPTION, false).getValue();
                }
            }
            if (result == null) {
                // read the title of the requested resource as fall back
                result = cms.readPropertyObject(
                    cms.getRequestContext().getUri(),
                    CmsPropertyDefinition.PROPERTY_DESCRIPTION,
                    true).getValue();
            }
        } catch (CmsException e) {
            // NOOP, result will be null
        }
        if (CmsStringUtil.isEmptyOrWhitespaceOnly(result)) {
            result = "";
        }
out.println(result);
%>

works like a charm!

cheers,
Andreas



Am 14.05.2013 um 11:10 schrieb Sandrine Prousteau <s.prousteau at eurelis.com>:

> Hi
> We have resolved this problem with a custom tag, inspired by the OpenCms tag "cms:info", and working with the properties Description and Keywords. It requires to create a custom CmsJspTagInfo, based on the OpenCms one, and complete it with the needed options.
> Sandrine
> 
> 
> -----Message d'origine-----
> De : opencms-dev-bounces at opencms.org [mailto:opencms-dev-bounces at opencms.org] De la part de Andreas Gily
> Envoyé : vendredi 10 mai 2013 17:14
> À : opencms-dev at opencms.org
> Objet : [opencms-dev] SEO description/keywords in meta-tags in detailpage
> 
> Hi list members,
> 
> My content is mostly made of "v8news"-like items in various .content folders.
> 
> I have to use SEO with meta-keywords and meta-description support. 
> In the XSD definition I've mapped title, description and keywords with their properties. 
> 
> When I access my news-item via detail-page, it works like a charm with the "Title" property. 
> Unfortunately the news-item properties for description and keywords are not shown, because there is no special <cms:info ... /> tag and <cms:property... /> only uses the properties from the enclosing structured content detail page...
> 
> <title><cms:info property="opencms.title" /></title> <meta name="description" content="<cms:property name="description" file="search" />"> <meta name="keywords" content="<cms:property name="keywords" file="search" />">
> 
> 
> I've been searching all day long, but I did not find any solution yet...
> 
> If there is no easy tag for this: is there a way to find out (with scriptlet code?), which news-item is currently displayed in a detail-page? 
> I thought about extracting the vfs url somehow and getting the property via: <cms:property name="Description" file="..." />
> 
> I've also thought about extracting the info inside the detail page formatter, but using jquery to modify the meta-tags after the page has loaded may not be the right solution, because crawlers may not use javascript...
> 
> 
> 
> Thanx in advance for some tips about this issue!
> 
> 
> cheers,
> 
> Andreas
> 
> 
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
> 
> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4151 bytes
Desc: not available
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20130515/80d2b204/attachment.bin>


More information about the opencms-dev mailing list