Translating URL Parameters in Multisite

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. :pray:t3:

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 %}

Try this code for the PHP version:

$params['category'] = array_get($otherModel, 'categories.0.slug');
$params['subcat'] = array_get($otherModel, 'categories.1.slug');

Unfortunately, it is still not working.

Output is that the :slug is translated but the :category and :subcat not.

I tried to change $params['slug'] = $otherModel->slug; into $params['slug'] = "test"; but nothing happened. Could it be an option that the overriding code is not working?

function onRun() is it inside a CMS component?

The code is added in the code section within a layout page (named blog.htm).
Markup is also in. the layout page (named blog.htm)

The URL /:category/:subcat/:slug is created with Tailor/Blueprints,

Try naming it function onStart()

Not working, unfortunately

Where is the sitePicker component located, in the layout also?

Yes, also in the layout.

Solved in OC update 3.6.17.

1 Like