Custom meta tag "description" in News

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
zener
New Member
New Member
Posts: 2
Joined: Tue Dec 22, 2015 11:37 am

Custom meta tag "description" in News

Post by zener »

Hi, I'm trying to have custom "meta description" tag in CMS Made Simple 2. I have in section this code and it works.

Code: Select all

<meta name="Description" content="{description}"> 
The problem is in News module. There isn't field to fill description tag. So I can't write description.

Any ideas? Thank you!
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Custom meta tag "description" in News

Post by Rolf »

In the top of the News Detail Template

Code: Select all

{$canonical = $entry->canonical scope=global}

{if empty($entry->content)}
    {$description = $entry->summary|strip_tags|strip|truncate:150 scope=global}
{else}
    {$description = $entry->content|strip_tags|strip|truncate:150 scope=global}
{/if}

{$page_title = $entry->title|cms_escape:htmlall scope=global}
Example Page Template

Code: Select all

{strip}
    {process_pagedata}
    {$canonical = "{$content_obj->GetURL()|lower|default:''}" scope=global}
    {$description = "{description}" scope=global}
    {$page_title = "{title}" scope=global}

    {$content = "{content}" scope=global}

    {if empty($description)}{$description = $content|strip_tags|strip|truncate:150|default:'' scope=global}{/if}
{/strip}<!DOCTYPE HTML>
< html lang="en">
<head>
    <meta name="description" content="{$description}">

    <link rel="canonical" href="{$canonical}">
</head>

< body>
    <h2>{$page_title}</h2>
    {$content}
< /body>
< /html>
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
zener
New Member
New Member
Posts: 2
Joined: Tue Dec 22, 2015 11:37 am

Re: Custom meta tag "description" in News

Post by zener »

THX for you reply but it doesn't work for me >:(

News Detail template

Code: Select all

{* News module entry object reference:
   ------------------------------
...
====
   Below, you will find the normal detail template information.  Modify this template as desired.
*}

{$canonical = $entry->canonical scope=global}

{if empty($entry->content)}
    {$description = $entry->summary|strip_tags|strip|truncate:150 scope=global}
{else}
    {$description = $entry->content|strip_tags|strip|truncate:150 scope=global}
{/if}

{$page_title = $entry->title|cms_escape:htmlall scope=global}



<h2>{$entry->title|cms_escape:htmlall}</h2>
Layout template

Code: Select all

{strip}
{process_pagedata}
    {$canonical = "{$content_obj->GetURL()|lower|default:''}" scope=global}
    {$description = "{description}" scope=global}
    {$page_title = "{title}" scope=global}



    {if empty($description)}{$description = $content|strip_tags|strip|truncate:150|default:'' scope=global}{/if}
{/strip}


{* == PROCESS DATA & HEAD == *}

{global_content name='Head'}


{* === BLACK BG === *}
<div id="page-bg">
  <div id="page">
HEAD section

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<__html lang="cs">
  <head>
    {metadata}
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <meta http-equiv="Content-Language" content="en">
    <meta name="Language" content="en">
    <meta name="Copyright" content="&copy; Site">
    <meta name="Robots" content="index,follow">
    <meta name="Author" content="ME">
    <meta name="Keywords" content="">
    <meta name="Description" content="{$description}">
    <meta name="viewport" content="width=device-width, initial-scale=1">
And the rendered page (any News)

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<__html lang="cs">
  <head>
    
<base href="http://example.cz/" />
<meta name="Generator" content="CMS Made Simple - Copyright (C) 2004-2015. All rights reserved." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <meta http-equiv="Content-Language" content="en">
    <meta name="Language" content="en">
    <meta name="Copyright" content="&copy; Site">
    <meta name="Robots" content="index,follow">
    <meta name="Author" content="Me">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
Any ideas? Thank you.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Custom meta tag "description" in News

Post by Rolf »

You haven't take over the {$content = "{content}" scope=global} and {$content} part from my example template above...
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Locked

Return to “CMSMS Core”