-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: Custom Fields for Sites #2790
Comments
Everything in Settings is restricted to admins only, for good reason, as anything you change in there could have significant consequences to the Craft install. It would be a little unnerving to manage content values right alongside those system settings. A Global Set with translatable fields seems like the right way to go for this. |
Makes sense. Thanks for considering this and explaining your rationale. I’ll post in Slack regarding how to access global sets for each site in a loop. I'm trying to create a site switcher with additional details about each site, e.g site logo, description, brand name etc. |
Actually, just realized it wasn’t really possible to query global sets in other sites. So I just added a {% for site in currentSite.group.sites %}
{% set global = craft.globalSets.handle('<globalSetHandle>').siteId(site.id).one() %}
<p>{{ global.<customFieldHandle> }}</p>
{% endfor %} |
Awesome! Thanks @brandonkelly! |
A drawback to this approach is that while any fields in a global set can be translatable, the fields and sets themselves are always going to show up, which can result in global fields/sets that don't necessarily apply to a particular site. E.g. I have a "Brands" site group with several similar-structured sites, but then another site that is a total one-off. If I add a "Brand logo" global field/set, it still shows up in the one-off site, even though it doesn't apply. My current solution is to also have "Brands" section, with entries matching the sites in my "Brands" site-group. Not great, but I like it better than the globals solution. I may pair that up with a field plugin that allows site selection, so I can then associate my "Brand" entry with a "Brand" site. Any input appreciated! @richhayler @brandonkelly |
Description
It would be great it you could add custom fields for sites in a multisite setup.
If you have the option to use the layout designer within the CP --> Settings --> Sites to configure custom fields that could be set per site and then render the data in a front-end template, e.g. site.description, site.primaryColour, site.twitter or currentSite.description, currentSite.primaryColour, currentSite.twitter etc.
Appreciate that "Globals" provides for this functionality but it makes more sense to me that site-specific fields might be better served being accessed from within the "sites" section? Also i'm not sure if you can access values of global fields (setup for each site) in a frontend template by looping through sites?
craft.app.sites.getAllSites()
?The text was updated successfully, but these errors were encountered: