1

I've got a bunch of entries in Site 1. I need to display them in Site 2. If I specify the site, I get the entries.

{% set entries = craft.entries.section('cenicNews').site('cenicOrg').limit(10) %}

However, they are pointing to Site 1's domain, using Site 1's template:

site1.com/news/new-library-initiative

I want them to be loaded on Site 2's domain, using Site 2's template:

site2.com/news/new-library-initiative

Note, if I remove the site parameter from my query, I get no results.

enter image description here

3

I figured it out!

  1. In Section settings > Propagation Method, you must choose 'Save entries to all sites enabled for this section', or, if you're using site groups, choose the appropriate group. This basically shares entries across multiple sites.
  2. If your entries were previously only associated with one site, doing this will cause entries to be resaved.
  3. When calling entries, do not specific the site from which they are pulled, in other words, do not include site or siteId in the entries query.

{% set entries = craft.entries.section('sectionName').limit(10) %}

Now your urls will be correct, relative to the current site.

On Site 1: firstSiteDomain.com/news/president-elect-not-sociopath-at-all-billions-rejoice

On Site 1: SecondSiteDomain.com/news/post/president-elect-not-sociopath-at-all-billions-rejoice

Even though the entries, news in this case, may be intended as "tied to" Site 1, you must 'share' them with Site 2 in order for Site 2 to load them and create entry.url correctly.

|improve this answer|||||
  • Aha! Then I completely misunderstood what you tried to do, and was thinking too complex. I thought you wanted to list entries from Site 2 on Site 1, but have them link to the full view on Site 2. Glad you found the solution! – KSP Dec 17 '19 at 16:24
2

I'm guessing a bit here, and I haven't tested it, but I would think once you load the entries in your template, they are entries just like any other, and Craft doesn't keep more track of where they came from.

This would be fine for just listing them, but I guess you want a link to see the full entry? I would guess you would need to keep track of the ones you loaded from the other site, and construct your link URL maunally and accordingly, possibly based on the other sites siteUrl, so for instance:

{% set otherSiteUrl = craft.entries.section('cenicNews').site('cenicOrg').siteUrl %}

And then use that to create the links you need.

|improve this answer|||||
  • I have considered manually constructing the links, but believe, based on the site settings (under section, per my image), that one should be able to access entry's URL based on the site in which it is loading. – 4midori Dec 14 '19 at 19:33
  • I’m pretty sure that this is not stored on the element itself. This is routing that only takes place on the request, given the current site. Once your in the context of one site, that is what it will use, and the entry is “decoupled” from it at this point. – KSP Dec 14 '19 at 21:15
  • In other words, it will pick the route based on the current site, and add the slug from the entry. If you make links with the other site’s siteUrl and add the entries’ slug, I’m pretty sure you’re good to go. – KSP Dec 14 '19 at 21:20
  • After all, the {slug} part of your routing is only referring to the slug attribute of your entry. – KSP Dec 14 '19 at 21:21
  • Thanks @ksp, I took another look at the propagation method for entries, and found the solution, noted below. – 4midori Dec 16 '19 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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