Meta descriptions from CGBlog through VAR field

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
personIsHere
Forum Members
Forum Members
Posts: 10
Joined: Thu Feb 15, 2018 10:37 am

Meta descriptions from CGBlog through VAR field

Post by personIsHere »

Hi,
I have the need for specific meta descriptions for each of my pages for the CGBlog pages.

I have created a new public field called description.

When referencing this in the template to check if all text inputs are displaying correctly, it works, with the statement

Code: Select all

{if isset($entry->fields)}
    {foreach $entry->fields as $field}
        <div class="CGBlogDetailField">
            {if $field->type == 'image'}
                <img src="{$entry->file_location}/{$field->value}"/>
            {else}
                <p>{$field->value}</p>
            {/if}
        </div>
    {/foreach}
{/if}
So that is ok, but based on trying to create global var at the bottom of the template,

Code: Select all

{assign var="description" value=$field->description|escape scope=global}
Here is my main page template,

Code: Select all

{if isset($description)}
        <meta name="description" content="{$description}">
{else}
        <meta name="description" content="Insert regular meta desc here...">
{/if}
Any help on why that last meta tag bit at the end is not working would be muchly appreciated... not quite sure where I've gone wrong, especially because I did EXACTLY the same thing for the title... :'(

Ta,
Jake
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Meta descriptions from CGBlog through VAR field

Post by velden »

So that is ok, but based on trying to create global var at the bottom of the template,

Code:
{assign var="description" value=$field->description|escape scope=global}
Probably, at the bottom of the field you're outside the foreach loop, hence the $field variable is non-existent anymore.

So better try:

So that is ok, but based on trying to create global var at the bottom of the template,

Code: Select all

{assign var="description" value=$entry->fields.description->value|escape scope=global}
Last edited by velden on Wed May 02, 2018 12:25 pm, edited 1 time in total.
Reason: changed code example
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Location: The Netherlands
Contact:

Re: Meta descriptions from CGBlog through VAR field

Post by Rolf »

- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
personIsHere
Forum Members
Forum Members
Posts: 10
Joined: Thu Feb 15, 2018 10:37 am

Re: Meta descriptions from CGBlog through VAR field

Post by personIsHere »

Velden you have once again saved my bacon ;D thank you very much!

Thanks as well Rolf for the article that was a valuable read!
Locked

Return to “Modules/Add-Ons”