ARCANEDEV / SEO-Helper

:mag: SEO Helper is a package that provides tools and helpers for SEO (Search Engine Optimization).
MIT License
322 stars 49 forks source link

blade usage #10

Closed mkibach closed 8 years ago

mkibach commented 8 years ago

hello, how to output result into blade.

I put this lines into my controller :

$title = new Title;
$title->set('Your awesome title');
echo $title->render();

this render the title before head tag, I need to set the title inside head to respect html strecture

can you help please ?

arcanedev-maroc commented 8 years ago

You can use the seo_helper() helper to achieve this.

In your Controller :

public function index()
{
    seo_helper()->setTitle('Your awesome title');

    return view('your-index-view');
}

In your view (or master view):

<!DOCTYPE html>
<html lang="en">
<head>
    {!! seo_helper()->render() !!}
</head>
<body>
    <!-- Your content -->
</body>
</html>
mkibach commented 8 years ago

hello, Thank you for your answer, your suggestion work fine for :

seo_helper()->setTitle('xxxxx');
seo_helper()->setDescription('yyyyy');
seo_helper()->setKeywords($keywords);

but not for :

seo_helper()->setSeoOpenGraph($openGraph);
seo_helper()->setSeoTwitter($seoTwitter);

I have created a seoTwiter instance of Card this way

$seoTwitter = new Card([
    'prefix' => 'twitter:',
    'card' => 'summary',
    'site' => '@ttttt',
    'metas' => [
        'creator' => '@ttttt',
        'url' => 'http://www.url.com',
        'image' => 'http://url.com/img/logo.png',
    ],
]);

I got this exception : ErrorException in SeoHelper.php line 138: Argument 1 passed to Arcanedev\SeoHelper\SeoHelper::setSeoTwitter() must implement interface Arcanedev\SeoHelper\Contracts\SeoTwitter, instance of Arcanedev\SeoHelper\Entities\Twitter\Card given, called in C:\lv-project\app\Http\Controllers\ContactController.php on line 48 and defined

arcanedev-maroc commented 8 years ago

Note : The Arcanedev\SeoHelper\SeoTwitter is the manager class to manage twitter tags (implements the Arcanedev\SeoHelper\Contracts\SeoTwitter interface) and the Arcanedev\SeoHelper\Entities\Twitter\Card is the card entity for twitter, same thing for opengraph.

So the correct way is to add the entity to the manager, like this:

use Arcanedev\SeoHelper\Entities\Twitter\Card;

$twitterCard = new Card([
    'prefix' => 'twitter:',
    'card' => 'summary',
    'site' => '@ttttt',
    'metas' => [
        'creator' => '@ttttt',
        'url' => 'http://www.url.com',
        'image' => 'http://url.com/img/logo.png',
    ],
]);

seo_helper()->twitter()->setCard($twitterCard);
mkibach commented 8 years ago

Thank you.