Another metadescription tag question - sorry

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
pwg
Forum Members
Forum Members
Posts: 191
Joined: Tue Aug 01, 2006 1:48 am

Another metadescription tag question - sorry

Post by pwg »

Hi,

I'm having an issue auto-generating my description tags.

In each page template I have:
{capture assign=metadescription}{content block="metadescription" label="META Description" oneline="true"}{/capture}
just before the </__html> tag.

In the metadata tag I have:

<meta name="description" content="{if isset($metadescription)}{$metadescription}{else}{$main_content|strip_tags|truncate:'200'|strip}{/if}"/>

The idea being, if the metadescription block is filled in, it displays that, if not, it grabs the first 200 words form the main_content block.
This seems to work on some of my sites, but not all?

Any suggestions?

Next, i'll try and get the og:image tag to auto generate..

Thanks for any help.

Cheers,
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Another metadescription tag question - sorry

Post by velden »

Why it doesn't work is hard to understand from this post.

First
This seems to work on some of my sites, but not all?
What 'does not work' mean exactly?

It's not clear what would be the difference between the installs. You should debug this by printing out the contents of the $metadescription variable.

Tips:

forum has

Code: Select all

[code] code tags
[/code]

Code: Select all

{capture assign=metadescription}{content block="metadescription" label="META Description" oneline="true"}{/capture}
it is said that using capture is less efficient than using the assign parameter on the tag if available:

Code: Select all

{content block="metadescription" label="META Description" oneline="true" assign="metadescription"}
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm

Re: Another metadescription tag question - sorry

Post by rotezecke »

wouldn't

Code: Select all

{if isset($metadescription)} 
always be true if it's assigned above?
try

Code: Select all

{if ! empty($metadescription)} 
pwg
Forum Members
Forum Members
Posts: 191
Joined: Tue Aug 01, 2006 1:48 am

Re: Another metadescription tag question - sorry

Post by pwg »

Doh. Many many thanks rotezecke.

Yep, that will do it, and thanks for the advice velden, I'll move them all away from the {capture} method.

I really do appreciate the help.

Cheers,

Paul
pwg
Forum Members
Forum Members
Posts: 191
Joined: Tue Aug 01, 2006 1:48 am

Re: Another metadescription tag question - sorry

Post by pwg »

Out of interest, I've seen some recommendations for the metadescription content block to be before and after the close body (<__body>) tag. Which is the recommended way?

Code: Select all

{content block="metadescription" label="META Description" oneline="true" assign="metadescription"}		
<__body>
</__html>
or

Code: Select all

<__body>
{content block="metadescription" label="META Description" oneline="true" assign="metadescription"}		
</__html>
Thanks again.
User avatar
rotezecke
Power Poster
Power Poster
Posts: 411
Joined: Fri Apr 18, 2008 9:34 pm

Re: Another metadescription tag question - sorry

Post by rotezecke »

neither makes sense.
while not necessary, i think it is good practice to assign content early in your template, before any html output.
pwg
Forum Members
Forum Members
Posts: 191
Joined: Tue Aug 01, 2006 1:48 am

Re: Another metadescription tag question - sorry

Post by pwg »

Thanks again, really do appreciate the help, even if I'm showing my ignorance at every turn!

Cheers,
Post Reply

Return to “The Lounge”