How Would I Get Home Page Meta Data On Another Page?

The home page isn't technically a "page" right? So I can't utilise the normal method using "fn_get_page_data".

{$_page_data = 1|fn_get_page_data}

I want to do this for a general business description on a contact page (local business schema).

Has anyone managed to do this? or could suggest how?

thanks

You can try this code:

{if $runtime.controller == 'pages' && $runtime.mode == 'view' && $smarty.request.page_id == 123}

{/if}

where 123 is the ID of the Contact Us page (can be found in the admin panel)

Hey, thanks for getting back to be, sorry if I was unclear, but I want to grab the home page meta data that is already set in the CMS:

https://www.dropbox.com/s/zu369yr71vujs1w/Screenshot%202016-01-14%2015.16.22.png?dl=0

I then want to output it on the contact page some how. I don't think I could access the homepage meta data with this could I?

I understand, but in this case additional code modifications will be required.

I don't quite understand how that last code will help, requesting $page.meta_description is going to return the contact page meta description?

What variable would I be using inside that IF to get the actual description?

Our solution assumes that you will just copy the description from admin panel and paste it to the mentioned code. I do not think that you often change meta description for the home page, right?

But if it does not suit you, additional custom development work is required.

I've got no problem with putting the markup on the contact page, I have managed that already in a custom block!

My problem is getting the meta data for the homepage from the CMS.

I do not want it hard-coded. This could be updated in future by a client or their SEO team.

I'm not sure if I understand correctly but CSC has a feature to copy the meta data to other pages that do not have meta data from the Default layout meta data information.

Try to use HTML block with Smarty support and the following code:

{$meta_description = $runtime.layout.layout_id|fn_get_home_meta_description}

and add PHP function to your addon:

function fn_get_home_meta_description($layout_id=0, $lang_code = CART_LANGUAGE)
{
    $meta_description = '';
    $home_location = db_get_field("SELECT location_id FROM ?:bm_locations WHERE dispatch = ?s AND layout_id = ?i", 'index.index', $layout_id);
    if (!empty($home_location)) {
        $meta_description = db_get_field("SELECT meta_description FROM ?:bm_locations_descriptions WHERE location_id = ?i AND lang_code = ?s", $home_location, $lang_code);
    }
    return $meta_description; 
}

(!) Not tested

@The Tool - Not really suitable as the page I'm trying to pull out the data on has its own meta data already which I do not want to alter.

@eComLabs - Helpful as always! Disappointing to resort to a custom query, but thank you works great! :-)

There is a built in method that will get that meta too, based on dispatch:

use Tygh\BlockManager\Location;

Location::instance()->get(‘index.index’);


If you have that in a general func stash, you can use it in Smarty just about anywhere by making a wrapper:

function fn_get_location_wrap($dispatch = ‘index.index’) {
return Location::instance()->get(‘index.index’);
}

True you can assign it to a view, but you can also grab it right from TPL with:

{$loc = fn_get_location_wrap()}
{$loc.meta_description}

Now, with the other method mentioned above, you need a layout ID. In order to get the layout ID: Registry::get(‘runtime.layout.layout_id’) at controllers/funcs or $runtime.layout.layout_id at smarty. If you are using schema as JSON-LD dont forget to clean it with SecurityHelper::sanitizeHtml() (use Tygh\Tools\SecurityHelper;)