Page 1 of 1

Another metadescription tag question - sorry

Posted: Thu Nov 06, 2014 2:45 am
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,

Re: Another metadescription tag question - sorry

Posted: Thu Nov 06, 2014 12:08 pm
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"}

Re: Another metadescription tag question - sorry

Posted: Thu Nov 06, 2014 5:43 pm
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)} 

Re: Another metadescription tag question - sorry

Posted: Thu Nov 06, 2014 6:18 pm
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

Re: Another metadescription tag question - sorry

Posted: Thu Nov 06, 2014 6:53 pm
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.

Re: Another metadescription tag question - sorry

Posted: Thu Nov 06, 2014 10:20 pm
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.

Re: Another metadescription tag question - sorry

Posted: Thu Nov 06, 2014 11:31 pm
by pwg
Thanks again, really do appreciate the help, even if I'm showing my ignorance at every turn!

Cheers,