Skip to content
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

Closed
richhayler opened this issue Apr 23, 2018 · 5 comments
Closed

FR: Custom Fields for Sites #2790

richhayler opened this issue Apr 23, 2018 · 5 comments

Comments

@richhayler
Copy link

richhayler commented Apr 23, 2018

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()?

@brandonkelly
Copy link
Member

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.

@richhayler
Copy link
Author

richhayler commented Apr 24, 2018

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.

brandonkelly added a commit that referenced this issue Apr 24, 2018
@brandonkelly
Copy link
Member

Actually, just realized it wasn’t really possible to query global sets in other sites. So I just added a craft.globalSets() method, similar to craft.entries(), for today’s 3.0.4 release. When that’s out you’ll be able to do this:

{% for site in currentSite.group.sites %}
    {% set global = craft.globalSets.handle('<globalSetHandle>').siteId(site.id).one() %}
    <p>{{ global.<customFieldHandle> }}</p>
{% endfor %}

@richhayler
Copy link
Author

Awesome! Thanks @brandonkelly!

@timkelty
Copy link
Contributor

timkelty commented May 9, 2018

A Global Set with translatable fields seems like the right way to go for this.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants