Message-ID: <319113841.3224.1485852436621.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3223_994766960.1485852436621" ------=_Part_3223_994766960.1485852436621 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html How to retrieve root location

How to retrieve root location

=20 =20

Description

Knowledge of the root location is important since it can be a starting p= oint for API queries, or even links to home page, but as eZ Platform can be= used for multisi= te development, the root location can vary.

By default, the root location ID is 2, but as it can be eas= ily be changed by configuration, the best practice is to retrieve i= t dynamically.

Retrieving ro= ot location ID

Root location ID can be retrieved easily from ConfigResolver. The parameter name is co= ntent.tree_root.location_id.

In a controller
=20
<?php
namespace Acme\TestBundle\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller;


class DefaultController extends Controller
{
    public function fooAction()
    {
        // ...
 
        $rootLocationId =3D $this->getConfigResolver()->getParameter(=
 'content.tree_root.location_id' );
 
        // ...
    }
}
=20

Retrieving t= he root location

From a template

Root location is exposed in the global Twig helper.

Making a link to homepage
=20
<a href=3D"{{ path( ezpublish.rootLocation ) }}" title=3D"L=
ink to homepage">Home page</a>
=20

From a controller

=20
<?php
namespace Acme\TestBundle\Controller;

use eZ\Bundle\EzPublishCoreBundle\Controller;

class DefaultController extends Controller
{
    public function fooAction()
    {
        // ...

        $rootLocation =3D $this->getRootLocation();

        // ...
    }
}
=20

 

 

------=_Part_3223_994766960.1485852436621--