Message-ID: <754291325.3060.1485851815329.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3059_311047693.1485851815312" ------=_Part_3059_311047693.1485851815312 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Cross SiteAccess links

Cross SiteAccess links

Version compatibility

This page is compatible with eZ Publish 5.3 / 2014.03

 

When using the multisite feature, it is sometimes useful to be = able to generate cross-links between the different sites.<= br> This allows to link different resources referenced in a same content re= pository, but configured independently with different tree roots.

Twig example
=20
 {# Linking a location #}=20
<a href=3D"{{ url( 'ez_urlalias', {'locationId': 42, 'siteaccess': 'some=
_siteaccess_name'} ) }}">{{ ez_content_name( content ) }}</a>

 {# Linking a regular route #}=20
<a href=3D"{{ url( "some_route_name", {"siteaccess": "some_siteaccess_na=
me"} ) }}">Hello world!</a>
=20
See=20 ez_urlalias documentation page
PHP example
=20
namespace Acme\TestBundle\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller as BaseController;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class MyController extends BaseController
{
    public function fooAction()
    {
        // ...

        $location =3D $this->getRepository()->getLocationService()-&g=
t;loadLocation( 123 );
        $locationUrl =3D $this->generateUrl(
            $location,
            array( 'siteaccess' =3D> 'some_siteaccess_name' ),
            UrlGeneratorInterface::ABSOLUTE_PATH
        );

        $regularRouteUrl =3D $this->generateUrl(
            'some_route_name',
            array( 'siteaccess' =3D> 'some_siteaccess_name' ),
            UrlGeneratorInterface::ABSOLUTE_PATH
        );

        // ...
    }
}
=20
 
Important: As SiteAccess matchers can involve hosts and po= rts, it is=20 highly recommended to generate cross-siteaccess
links in the absolute form (e.g. using=20 url() Twig helper).

To implement this feature, a new VersatileMatcher was added= to allow SiteAccess matchers to be able to reverse-match.
All= existing matchers implement this new interface, except the Regexp based ma= tchers which have been deprecated.

The SiteAccess router has been added a matchByName() method= to reflect this addition. Abstract URLGenerator and DefaultRouter have been updated as well.

Note: SiteAccess router public methods have also been extr= acted to a new interface,=20 SiteAccessRouterInterface.
------=_Part_3059_311047693.1485851815312--