Last active
January 11, 2017 11:20
-
-
Save escuccim/5316a553a085eca6e8b9ce8119a73837 to your computer and use it in GitHub Desktop.
Laravel helper function to get translated page title and description from lang file metadata.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getMetaData($type){ | |
// set a default so it doesn't break phpunit | |
if(isset($_SERVER['REQUEST_URI'])) | |
$page = $_SERVER['REQUEST_URI']; | |
else | |
$page = "/"; | |
// if we are looking at a blog article just use the default for the main blog page | |
if(strpos($page, 'blog') !== false) { | |
$page = '/blog'; | |
} | |
// get the data from the lang files | |
$data = trans('metadata.' . $page . '-' . $type); | |
// if the key doesn't exist use the default | |
if($data == 'metadata.' . $page . '-' . $type) { | |
$data = trans('metadata.default-' . $type); | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment