Unverified Commit 329141a2 authored by Nicolas Widart's avatar Nicolas Widart Committed by GitHub

Merge pull request #635 from ChristianGiupponi/master

Possibile fix for alternate variable not set in page
parents b601dd31 0357459e
...@@ -13,10 +13,25 @@ abstract class BasePublicController extends Controller ...@@ -13,10 +13,25 @@ abstract class BasePublicController extends Controller
*/ */
protected $auth; protected $auth;
public $locale; public $locale;
public $alternateUrls = [];
public function __construct() public function __construct()
{ {
$this->locale = App::getLocale(); $this->locale = App::getLocale();
$this->auth = app(Authentication::class); $this->auth = app(Authentication::class);
view()->share('alternate', $this->alternateUrls);
} }
/**
* Add alternate URLs to main array and inject it to the page
*
* @param array $alternateUrls
* @return void
*/
protected function addAlternateUrls(array $alternateUrls)
{
$this->alternateUrls = array_merge($this->alternateUrls, $alternateUrls);
view()->share('alternate', $this->alternateUrls);
}
}
} }
...@@ -46,9 +46,9 @@ class PublicController extends BasePublicController ...@@ -46,9 +46,9 @@ class PublicController extends BasePublicController
$template = $this->getTemplateForPage($page); $template = $this->getTemplateForPage($page);
$alternate = $this->getAlternateMetaData($page); $this->addAlternateUrls($this->getAlternateMetaData($page));
return view($template, compact('page', 'alternate')); return view($template, compact('page'));
} }
/** /**
...@@ -62,9 +62,9 @@ class PublicController extends BasePublicController ...@@ -62,9 +62,9 @@ class PublicController extends BasePublicController
$template = $this->getTemplateForPage($page); $template = $this->getTemplateForPage($page);
$alternate = $this->getAlternateMetaData($page); $this->addAlternateUrls($this->getAlternateMetaData($page));
return view($template, compact('page', 'alternate')); return view($template, compact('page'));
} }
/** /**
......
...@@ -7,9 +7,11 @@ ...@@ -7,9 +7,11 @@
@show @show
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<title>@section('title')@setting('core::site-name')@show</title> <title>@section('title')@setting('core::site-name')@show</title>
@foreach($alternate as $alternateLocale=>$alternateSlug) @if(isset($alternate))
<link rel="alternate" hreflang="{{$alternateLocale}}" href="{{url($alternateLocale.'/'.$alternateSlug)}}"> @foreach($alternate as $alternateLocale=>$alternateSlug)
@endforeach <link rel="alternate" hreflang="{{$alternateLocale}}" href="{{url($alternateLocale.'/'.$alternateSlug)}}">
@endforeach
@endif
<link rel="canonical" href="{{url()->current()}}" /> <link rel="canonical" href="{{url()->current()}}" />
<link rel="shortcut icon" href="{{ Theme::url('favicon.ico') }}"> <link rel="shortcut icon" href="{{ Theme::url('favicon.ico') }}">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment