Siteaccess operators
Three classes registered in kernel/common/eztemplateautoload.php give templates the addresses and names of the
other siteaccesses of the installation.
| Operator | Class and file | Work done by |
|---|---|---|
siteaccess_url | ezpSiteAccessURLOperator, kernel/common/ezpsiteaccessurloperator.php | ezpSiteAccessURL (kernel/private/classes/ezpsiteaccessurl.php) |
siteaccess_menu, siteaccess_menu_key | ezpSiteAccessMenuOperator, kernel/common/ezpsiteaccessmenuoperator.php | ezpSiteAccessMenu (kernel/private/classes/ezpsiteaccessmenu.php) |
language_switcher | ezpLanguageSwitcherOperator, kernel/private/eztemplate/ezplanguageswitcheroperator.php | the class of [RegionalSettings] LanguageSwitcherClass |
The examples ran on the command line, so the scheme is http and the host comes from the settings.
Contents
- The operators: siteaccess_url, siteaccess_menu, siteaccess_menu_key, language_switcher
- Compiled templates
The operators
siteaccess_url
Generated page: siteaccess_url.
| Parameter | Type | Required | Default |
|---|---|---|---|
siteaccess | string | no | empty |
- Input: none.
- Returns: the front page address of a siteaccess, ending in
/, as a string. Without a name it is the front page of the site the current siteaccess belongs to (ezpSiteAccessURL::front()):[SiteSettings] FrontSiteAccessof the current siteaccess (an administration names its site there), elseDefaultAccess. A siteaccess that is not inAvailableSiteAccessList[]gives an empty string.
The address is worked out from the scheme, host and port of the request and the way the target siteaccess is matched
(MatchOrder with host_uri, host and uri; URIMatchType, HostUriMatchMapItems, HostMatchMapItems, and the
siteaccess's own [SiteSettings] SiteURL), so it works for URI, host, host and URI, and port matching alike. An
address is only used when the matching rules lead it to that siteaccess with nothing of the path left over, so a
host-matched site never gets a /name/ path that its host would read as a module (and answer 404). In this order:
- this host, with a
HostUriMatchMapItemsentry of the siteaccess for this host, else with its URI element (or itsURIMatchMapItemskey); - the siteaccess's own
SiteURL(host, port and path; an index file in it is left out), unless it is empty orlocalhost; - a host that
HostMatchMapItemsmaps to it, without a path; - the host and URI of one of its
HostUriMatchMapItemsentries.
When none of them can be shown to lead there, its URI on this host is used, else its SiteURL as written, else this
host. The scheme is always the one of the request. With the settings of a demo whose administration has a host of
its own (MatchOrder=host_uri;host;uri, HostMatchMapItems[]=edit.example.com;admin and =example.com;site,
HostUriMatchMapItems[]=example.com;bold;bold;strict), the administration on edit.example.com links site to
https://example.com/ and bold to https://example.com/bold/. It is not quoted and not escaped.
1 front: siteaccess_url()
2 bold: siteaccess_url( 'bold' )
3 starter_ger: siteaccess_url( 'starter_ger' )
4 not available: siteaccess_url( 'nosuchsite' )|get_typeOutput:
1 front: http://www.example.com/site/
2 bold: http://www.example.com/bold/
3 starter_ger: http://www.example.com/starter_ger/
4 not available: string[0]siteaccess_menu
Generated page: siteaccess_menu.
| Parameter | Type | Required | Default |
|---|---|---|---|
user | object | no | null |
- Input: none.
- Returns: a hash with
enabled(bool),front(the item of the site the globe button opens) andgroups(a list of hashes withidentifier,siteoradmin, anditems). An item is a hash withidentifier,name(SiteName, else the identifier),locale,lang,url,display_url(without the scheme and trailing slash),currentandadmin.
It is the data of the globe button in the admin4 and admin4l headers, configured in site.ini
[AdminSiteAccessMenu] of the administration siteaccess: Show, List (related uses RelatedSiteAccessList[],
available uses AvailableSiteAccessList[]), HiddenSiteAccessList[], AdminSiteAccessList[] and
ListAdministrations. With a user, a siteaccess other than the front site is listed only when that user may log in
there (eZUser::canLoginToSiteAccess()); the admin templates pass $current_user.
Rendered on the admin siteaccess without a user:
def $menu = siteaccess_menu()
enabled=$menu.enabled|choose( 'no', 'yes' ) key length=siteaccess_menu_key()|count_chars
front: $menu.front.identifier $menu.front.display_url
foreach $menu.groups as $group
$group.identifier: foreach $group.items as $item$item.identifier ($item.locale)delimiter, /delimiter/foreach
/foreachOutput:
enabled=yes key length=32
front: site admin.example.com/site
site: bold (eng-US), bold_ger (ger-DE), editor (eng-US), starter (eng-US), starter_ger (ger-DE)siteaccess_menu_key
Generated page: siteaccess_menu_key.
- Input: none. Parameters: none.
- Returns: an MD5 string for cache-block keys (an empty string when the menu is switched off). It changes with
the listed siteaccesses, the administration list, the front siteaccess, the current siteaccess, and the scheme, host
and port of the request, so a cached header shows the right menu. Line 1 of the example above shows its length. The
key reads no setting of the listed siteaccesses themselves: a changed
SiteNameorLocaleof one of them shows after the template caches of the administration are cleared.
language_switcher
Generated page: language_switcher.
| Parameter | Type | Required | Default |
|---|---|---|---|
destination | string | no | empty |
- Input: none.
- Returns: what
setupTranslationSAList()of the class in[RegionalSettings] LanguageSwitcherClassreturns, or nothing when the setting is missing. The kernel'sezpLanguageSwitcherreturns one entry per[RegionalSettings] TranslationSA[<siteaccess>]=<name>: a hash withurl(/switchlanguage/to/<siteaccess>/plus the destination),text(the name) andlocale(ContentObjectLocaleof that siteaccess). An empty array whenTranslationSAis not set.
When the destination has no ?, the query string of the current request is appended to it. The url is a path for
ezurl, which adds the current siteaccess prefix; the switchlanguage/to view (kernel/private/modules/switchlanguage/to.php) asks the same
class for the address of the destination in the other siteaccess and redirects there. On a development installation only some siteaccesses
set TranslationSA; rendered on starter:
TranslationSA has ezini( 'RegionalSettings', 'TranslationSA' )|count entries
foreach language_switcher( 'privacy-policy' ) as $sa => $lang
$sa: $lang.text $lang.locale $lang.url
/foreachOutput:
TranslationSA has 2 entries
starter: English eng-US /switchlanguage/to/starter/privacy-policy
starter_ger: Deutsch ger-DE /switchlanguage/to/starter_ger/privacy-policyCompiled templates
siteaccess_url, siteaccess_menu and siteaccess_menu_key have template hints with transformations: the compiler
writes a direct call (ezpSiteAccessURL::root() or front(), ezpSiteAccessMenu::current(),
ezpSiteAccessMenu::key()) into the compiled template, so they cost no operator lookup at run time and are evaluated
on every run, never at compile time. language_switcher has no hints and runs through modify().
Related pages
- URL, design, INI and HTTP operators
- Content languages
- All template operators (generated)
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.