2

In Craft 3 Sites, there are some default fields like language, handle, etc.

I would like to add additional fields. Is this possible. Specifically, I want to add an Image field so we can add a flag that we will use in the front end switcher. We also use Geo location and the Geo location databases have their own country identifiers (e.g. Maxmind returns GB for UK), and so I would like to have a field for the Maxmind country code when creating a site so we can match it.

Is this possible? I could probably create a new channel or globals in which we can enter the Site handle, then fetch this data for the site on the front end, but it would be cleaner to have additional fields in the Sites settings.

Thanks

1 Answer 1

2

I would say the easiest thing is to create a set of Globals with all site specific settings. You can include custom settings for sites via Behaviors and Events and include your custom HTML and run custom logic to store those values in custom tables but I doubt it's worth it. A global set should be fine.

By the way: GlobalSets are site specific - you don't need to include a site handle or something. Just insert different settings for each site, Craft will fetch the correct one by itself.

If you want to loop a set for all sites

{% for site in craft.app.getSites().getAllSites() %}
    {% set globalSet = craft.app.globals.getSetByHandle('myset', site.id) %}
    {{ globalSet.myValue }}
{% endfor %}
2
  • Ah so I wont need to do any relationships between globals and the Sites. This is what put me off. But without relationships, then it becomes easier and I guess the same coding needed even if it were in the sites settings. So sound like it will be fine, thanks. Although it would be cleaner to have all the sites settings in one place though. Commented Apr 1, 2019 at 11:56
  • You could create a matrix then and create a custom field type that is able to select sites, then you create a new block for each site Commented Apr 1, 2019 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.