Page 1 of 1

Meta descriptions from CGBlog through VAR field

Posted: Wed May 02, 2018 11:25 am
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

Re: Meta descriptions from CGBlog through VAR field

Posted: Wed May 02, 2018 12:14 pm
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}

Re: Meta descriptions from CGBlog through VAR field

Posted: Wed May 02, 2018 12:20 pm
by Rolf

Re: Meta descriptions from CGBlog through VAR field

Posted: Wed May 02, 2018 2:01 pm
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!