Implement shadow namespaces, which refers to the concept where if a local page doesn't exist, it will be transparently fetched from a remote wiki.
For example, if Template:Hi does not exist on wiki A but it exists on the linked wiki B, then if {{Hi}} is added to a page on wiki A, then it will show Template:Hi from wiki B.
This is just like how InstantCommons and foreign file repos currently work (If [[File:Example.png]] does not exist on this wiki, but exists on Wikimedia Commons, the Commons wiki image is retrieved and used).
For more details see https://www.mediawiki.org/wiki/Requests_for_comment/Shadow_namespaces