Hi everyone,
I want to implement alternate URLs in my . It works perfectly for every CMS page except my blog post
as I’m struggling to change the params correctly.
The URL structure of the CMS page is /:category/:subcat/:slug
This is what I can think of (with help from this doc: Site Picker - October CMS - 3.x)
but I need a little help from this community.
function onRun() {
$myModel = MyModel::find(1);
$otherModels = $myModel->newOtherSiteQuery()->get();
Event::listen('cms.sitePicker.overrideParams', function($page, $params, $currentSite, $proposedSite) use ($otherModels) {
$otherModel = $otherModels->where('site_id', $proposedSite->id)->first();
if ($otherModel) {
$params['id'] = $otherModel->id;
$params['slug'] = $otherModel->slug;
$params['fullslug'] = $otherModel->fullslug;
$params['category'] = $otherModel->categories.0.slug;
$params['subcat'] = $otherModel->categories.1.slug;
}
return $params;
});
}
The categories.1.slug
is been used like this in the blueprint.
pagefinder:
# context: item
replacements:
subcat: categories.1.slug
category: categories.0.slug
To be complete, this is the markup
{% for site in multisite.sites %}
{% if site.locale == 'nl' %}
<link rel="canonical" href="{{ placeholder('metaCanonical')? : site.url }}" />
<link rel="alternate" hreflang="x-default" href="{{ site.url }}" />
{% endif %}
<link rel="alternate" hreflang="{{ site.locale }}" href="{{ site.url }}" />
{% endfor %}