Wagtail MultiSite - Cross posting content

感情迁移 提交于 2019-12-10 10:30:58

问题


I am currently building two sites out of a single Wagtail installation. The sites are for a company and it's sister company and there is some overlap in content. Ideally we don't want to have to post the same content twice. In particular we have an Events page on both sites and there may be events that are relevant to both companies.

The problem is that a Wagtail page can only exist in one place in the tree at once. I have considered creating a "MirroredEventPage" model with only one foreign key field to the original EventPage model, although this approach has it's problems when it comes to writing the EventIndex page and reusing templates.

I've also considered creating Events as a vanilla Django model which isn't ideal either.

Has anyone had a similar issue and found a good solution?


回答1:


An idea would be to use a mix of using Wagtail Snippets and the RoutablePageMixin on your Events Index Pages.

1. Make an Events Snippet

Make the shared content of your Events page into a Wagtail Snippet. You will loose the ability to access versions of changes but gain the ability to share across sites.

http://docs.wagtail.io/en/v1.13/topics/snippets.html

2. Update your Events Index page model to use the RoutablePageMixin

http://docs.wagtail.io/en/v1.13/reference/contrib/routablepage.html

You can then hook into the URL calls for any of the Events Index pages if they have something like mydomain.com/events/123-event-name-as-slug. This can load a custom template (which can be shared or not, depending on the site), with the events index and the event snippet sent via the context.

These URLs will be their own unique URL but not actually have a page behind them. Remember to consider your SEO implications, ensure that the admin editors can manage things like meta description on the snippet (or work through how that will propagate automatically).

You can also hook into the Wagtail button (called Wagtail Userbar) so that when editors click the front end Wagtail button and click 'edit Event' it can take them directly to the Snippet editing page in admin.

http://docs.wagtail.io/en/v1.13/reference/hooks.html#construct-wagtail-userbar

3. Update Events Index Listing

If there are some events you do not want on both sites, you could add checkboxes (both ticked by default) for the two sites you operate. This means the Events Index page will only show the events relevant to that site.

You can do this by overriding the serve method on the page model.

Note: In this example you are not explicitly linking each and every event to each site's event index page. You are simply loading a query of relevant events and passing it to the events index template.

4. More Complex Integration

If you really want an individual page for each 'Event' under each site, you could create a custom signal on Snippet create/edit/delete.

Intro to Wagtail Signals: http://docs.wagtail.io/en/v1.13/reference/signals.html

You would want to ensure that the fields are non-editable on the Page edit, but would be editable under snippets. Then you just keep things in sync with your signals, bit messy but gives you an actual 'Page' in the Admin.



来源:https://stackoverflow.com/questions/44953972/wagtail-multisite-cross-posting-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!