{xseo[:level]}

Description

Reads one directory segment from the current SEO-friendly URL path, as parsed by the site module router (AA_Router_Seo). The router splits a path like /en/about-us/projects/efficiency into language plus numbered segments xseo1, xseo2, xseo3 and so on; xseo (with no number) is an alias for the last segment. With no argument the command returns the last segment; with a digit it returns that level (xseo:1 is the first directory level, xseo:2 the second, and so on). A non-digit argument is treated as no argument and returns the last segment. The value is read live from the router state and is never cached, so it depends entirely on the URL of the page being viewed; outside a site-module router page it returns an empty string. Typical use is highlighting the active item in a menu by comparing a segment to each item SEO slug, or building links and switching content per URL level. The matching ID reader is xid (xid returns the item id behind the same segment).

Parameters

level optional default (none - returns the last segment)

The directory level to read, counting from the start of the path. 1 is the first segment after the language, 2 the second, and so on. With no argument (the default) the command returns the last segment, equivalent to the bare variable xseo. A non-digit argument is ignored and also returns the last segment.

Allowed values empty = last segment (alias of the bare xseo variable); 1, 2, 3 ... = that directory level counted from the start of the path; any non-digit = treated as empty

Examples

virtual{ifeq:{xseo}:home:You are on the home page:Some other page}
ExpectedYou are on the home page (when the URL last segment is home; otherwise Some other page)
ActualSome other page
Compares the last URL segment to home to show home-page-only content. A common real-world pattern in site templates.
virtual<a href="/en/about-us"{ifeq:{xseo:1}:about-us: class="active"}>About us</a>
ExpectedAbout us (the active class is added when the first level equals about-us)
About us (the active class is added when the first level equals about-us)">ActualAbout us
The most common use: compare a URL level (here the first, xseo:1) to a menu item slug and add an active class when they match. In real menus the slug comes from each item field, e.g. {ifeq:{xseo:1}:{seo.............}: class=active}.
virtualSection: [{xseo}]
ExpectedSection: [efficiency] (the last path segment; empty off a router page)
ActualSection: [xseo]
Returns the last directory segment of the current SEO URL. Runtime-dependent on the page URL; empty outside a router page.
virtualFallback: [{xseo:all}]
ExpectedFallback: [efficiency] (non-digit argument returns the last segment)
ActualFallback: [xseo]
A non-digit argument is treated as no argument, so this returns the last segment, same as bare xseo.
virtualFirst level: [{xseo:1}]
ExpectedFirst level: [about-us] (first path level; empty off a router page)
ActualFirst level: [expression]
Returns the first directory level after the language. Same as the bare variable xseo1. For /en/about-us/projects this is about-us.
virtualThird level: [{xseo:3}]
ExpectedThird level: [efficiency] (third path level; empty if the path is shorter)
ActualThird level: []
Returns the third directory level. For /en/about-us/projects/efficiency this is efficiency.