Info Changes Based On Page Type

I need a way to change meta data depending if I'm on a product vs category page vs other types of pages. I should be able to ad a {if statement to test for page type. I just can't find any examples to work from.



Any help would be appreciated,



David

Hello dsdewitt,



Let me explain. In URL you have the following parameter: dispatch=controller.mode Even if you enabled SEO addon, the system rewrites the .html URLs with the appropriate dispatch parameter and sends it to PHP script. So, if you want to check if you are on the “page” or “category” page you should check the “$controller” variable in template (e.g. {if $controller == 'categories'} or {if $controller == 'pages'} or {if $controller == 'products'} etc.).



However, there is another way to setup meta data to these pages. The admin is able to specify meta data by editing the Block location on the Layouts page in admin panel. Please have a look.



Hope it will be helpful for you.

My suggestion is not to do a tpl modification, the best way is hook to controllers and update 3 variables(page_title, meta_description, meta_keywords) with the help of my_changes add-on, for this you need to do



#add files (for cs-cart 4.x)[list]

[]app/addons/my_changes/controllers/frontend/categories.post.php

[
]app/addons/my_changes/controllers/frontend/products.post.php

[*]app/addons/my_changes/controllers/frontend/pages.post.php

[/list]



#content for all files because are using the same view but for every page category_id, product_id and page_id is different sow you will need to take that in consideration

```php

/*****************************************************************
* *
* (c) 2014 hungryweb.net | support at yum@hungryweb.net *
* *
*****************************************************************/
use Tygh\Registry;
if (!defined('BOOTSTRAP')) { die('Access denied'); }
if($mode=='view'){
$page_title = 'TITLE';
$meta_description = 'DESCRIPTION';
$meta_keywords = 'KEYWORDS';

Registry::get('view')->assign('page_title', $page_title);
Registry::get('view')->assign('meta_description', $meta_description);
Registry::get('view')->assign('meta_keywords', $meta_keywords);

}
```

I hope that helps,

---
Valentin
[color=#808080][size=2]part of hungryweb.net[/size][/color]

Thanks eComlabs.

The {if $controller statements was what I was trying to find. I needed this to have some meta og: statements only show on the product page for pinterest rich pins. I just added the following hook to: /skins/myskin/customer/addons/my_changes/hooks/index/meta.post.tpl



{if $controller == 'products'}

{if $product.discount}

{/if}


{/if}




Thanks for all your help,

David DeWitt

You are welcome!