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

Retrieving root location

=20
=20
=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 multisite 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.

Solution

Retrieving root = location ID

Root location ID can be retrieved easily from  ConfigResolver. The = parameter name is  content.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 the = 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

 

 

=20
=20
=20
=20

In this topic:

=20
=20
=20
------=_Part_2781_549846870.1485850782382--