Forums / Setup & design / Page refresh causes custom meta tags, etc. to disappear

Page refresh causes custom meta tags, etc. to disappear

Author Message

Luis Cruz

Friday 09 June 2006 1:09:09 pm

For reference, running ez 3.6.3.

Following the directions in ">this post ( http://ez.no/community/forum/developer/meta_description_tag ), I created for the various objects in the system the following fields:
meta keywords
meta description
html page title

In page_head.tpl, the code checks the current node for these fields; if they are present and not empty strings, it uses those values for the meta data and page title. Otherwise, it uses the default behavior of eZ publish. Complete code of page_head.tpl listed below.

Now, it works fine if I flush the cache and load the page up for the first time. The meta tags and page title display as expected. However, any subsequent page loads cause the page to revert back to the default behavior. Throwing in a debug print-out shows that the first page load treats $node as a complete object; any page load after that shows $node to be empty.

Is this a caching (or lack thereof) issue? I don't have a cache block around the inclusion of the page head in pagelayout.tpl. Can't see anything in the log files indicating an error. Stumped on this one.

Thanks in advance.

page_head.tpl

{*?template charset=utf-8?*}
{default enable_help=true() enable_link=true()}

{let name=Path
     path=$module_result.path
     reverse_path=array()}
  {section show=is_set($module_result.title_path)}
    {set path=$module_result.title_path}
  {/section}
  {section loop=$:path}
    {set reverse_path=$:reverse_path|array_prepend($:item)}
  {/section}
{if and(is_set($node.data_map.html_page_title), ne($node.data_map.html_page_title, ""))}
        {set-block scope=root variable=site_title}{$node.data_map.html_page_title.content}{/set-block}
{else}
        {set-block scope=root variable=site_title}
                {section loop=$Path:path}{$:item.text|wash}{delimiter} / {/delimiter}{/section} - The Quickest Way to Secure Your Network
        {/set-block}
{/if}
{/let}

    <title>{$site_title}</title>

    {section show=and(is_set($#Header:extra_data),is_array($#Header:extra_data))}
      {section name=ExtraData loop=$#Header:extra_data}
      {$:item}
      {/section}
    {/section}
    
    {* check if we need a http-equiv refresh *}
    {section show=$site.redirect}
    <meta http-equiv="Refresh" content="{$site.redirect.timer}; URL={$site.redirect.location}" />
    
    {/section}
    
    {section name=HTTP loop=$site.http_equiv}
    <meta http-equiv="{$HTTP:key|wash}" content="{$HTTP:item|wash}" />
    
    {/section}
    
    {section name=meta loop=$site.meta}
        {switch match=$meta:key|wash()}
        {case match=description}
                {if and(is_set($node.data_map.meta_description), ne($node.data_map.meta_description, ""))}
    <meta name="{$meta:key|wash}" content="{$node.data_map.meta_description.content}" />
                {else}
    <meta name="{$meta:key|wash}" content="{$meta:item|wash}" />
                {/if}
        {/case}
        {case match=keywords}
                {if and(is_set($node.data_map.meta_keywords), ne($node.data_map.meta_keywords, ""))}
    <meta name="{$meta:key|wash}" content="{$node.data_map.meta_keywords.content}" />
                {else}
    <meta name="{$meta:key|wash}" content="{$meta:item|wash}" />
                {/if}
        {/case}
        {case}
    <meta name="{$meta:key|wash}" content="{$meta:item|wash}" />
        {/case}
        {/switch}
    {/section}

    <meta name="MSSmartTagsPreventParsing" content="TRUE" />
    <meta name="generator" content="eZ publish" />

{section show=$enable_link}
    {include uri="design:link.tpl" enable_help=$enable_help enable_link=$enable_link}
{/section}

{/default}

Kristof Coomans

Friday 09 June 2006 11:49:43 pm

Hi Luis

If content view caching is enabled, $node is only available in the pagelayout when the cache isn't available. As soon as content/view can use the cached view, then $node isn't available anymore in the pagelayout.

The node id however is always available (for content/view) in the pagelayout in $module_result.node_id. You can fetch the node then with something like

{let $nd_id=$module_result.node_id
     $nd=fetch('content','node',hash('node_id',$nd_id))}

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Luis Cruz

Monday 12 June 2006 7:25:58 am

That did the trick; one more useful bit of info. to file away.

Thanks, Kristof!

Cheers.