Site based content

I’m trying to setup site based content.

In my model I have:

public function getMainSiteOptions() {
        return \Site::listSites()->pluck('name', 'code');
}

With the field:

main_site:
        label: Site
        span: full
        showSearch: true
        type: dropdown

Now I would like to have the specific site code defined in a subdomain, e.g.:
https://2023.duchenne.info

The site code would also be a year and with this I would need to parse a defined URL with the subdomain to get the site specific content.

This could look like this:

public function portraits() {
        return PortraitModel::where('main_site', $current_subdomain)->get(); // how to get $current_subdomain?
}

Is there a way I could get my $current_subdomain dynamically?

Hi,

I believe you can do all that using the site definitions

have a look at the doc here : Site Manager - October CMS - 3.x

Yes, true, thanks. I can use:

$site = \Site::getActiveSite();
$portraits = PortraitModel::where('main_site', $site->code)->get(); // $site->code can then match with the subdomain
1 Like

I believe you dont even need to write this sort of code by simply using the trait Multisite to your model.

Thanks, works like charm.

I’ve added this to my model:

use \October\Rain\Database\Traits\Multisite;
protected $propagatable = [];

Do you know, if this Multisite Trait could also work for tailor?

1 Like

yes it does work with Tailor as well
check the documentation here Blueprints - October CMS - 3.x
scroll down into the table and look for a row named multisite

2 Likes