Forums / Setup & design / Meta description & Keywords

Meta description & Keywords

Author Message

Alejandro Dominguez

Wednesday 09 February 2011 4:55:30 am

I'm using eZ 4.4 with eZFlow. I have created a class for news where I had two atributtes for the metatags, description & keywords. I don't know what I should do to display this metatags in the header.

I thought a template override for page_head.tpl can be the right idea. What do you think?

cheers,

Alejandro

Guillaume Kulakowski

Wednesday 09 February 2011 6:28:31 am

"

 

I thought a template override for page_head.tpl can be the right idea. What do you think?

"

Use template fallback : http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Concepts-and-basics/Designs/Design-combinations/%28language%29/eng-GB

My blog : http://www.llaumgui.com (not in eZ Publish ;-))
eZC on RHEL : http://blog.famillecollet.com/pages/Config-en
eZC on Fedora : just "yum install php-channel-ezc"

Gaetano Giunta

Wednesday 09 February 2011 12:46:34 pm

As Guillaume said, a template fallback is enough, in the sense that your new template will be used in every case. Teplate overrides are only used when specific conditions match.

In your new page_head.tpl you can fetch current object and get the attributes for meta tags, but that will be expensive in sql queries, ram and cpu.

So you should add a cache-block around that part (quick and dirty fix), or, better, rely on usage of the persistent variable (look up in the forums and tutorials on how to do it)

Principal Consultant International Business
Member of the Community Project Board

Alejandro Dominguez

Thursday 10 February 2011 2:45:33 am

Hello guys,

thanks for your quick answer. I solve this problem with an override of pagelayout.tpl

This is my code. It can be helpfull for other users

{def $node_id=$module_result.node_id
$node=fetch( 'content', 'node', hash('node_id', $node_id ) )}
<meta name="keywords" content="{attribute_view_gui attribute=$node.object.data_map.meta_keywords}" />
<meta name="description" content="{attribute_view_gui attribute=$node.object.data_map.meta_description}" />

Another question: I got this output in both metatags

Theres is an enter between " and key1. any ideas of how I can avoid this? I think this must be easy but I can't find the solution.

<meta name="keywords" content="

key1,key2,key3" />

Franck Magnan

Thursday 10 February 2011 3:30:58 am

Hello Alejandro,

when you use the "attribute_view_gui" operator, eZ Publish call most suitable template file to display your attribute. If you want to know which template file is loaded for meta_keywords datatype, you can enable output debug and template output for your siteaccess. Then, you will see which template file is loaded in the source code of your page. This give you a lead to find why you have a line return in your code.

You can also decide to not use attribute_view_gui operator and modify your code to get this :

{if $node.object.data_map.meta_keywords.has_content}
    <meta name="keywords" content="{$node.object.data_map.meta_keywords.content|wash()}" />
{/if}
{if $node.object.data_map.meta_description.has_content}
    <meta name="description" content="{$node.object.data_map.meta_description.content|wash()}" />
{/if}

hope this help

--
Developer at Open Wide