Writing document path expressions
Path expressions allow you to select a set of documents from the content tree of Kentico websites. The expressions are based on the alias path values of documents. You can use two types of path values:
- Exact paths of individual documents
- Expressions containing special characters that specify multiple documents or relative paths
You need to use path expressions in the Path property of web parts or controls that load data from documents (document data sources, document listings with built-in data sources, navigation components).
Using wildcard characters (% and _)
The % wildcard represents any number of characters.Add the wildcard to the end of the path to select all documents under the specified section of the site.
Examples:
- / - only the root document
- /% - all documents
- /Products - only the Products document
- /Products/% - all child documents under the Products document
The _ wildcard represents a single character. For example:
- /Product_ - selects documents /ProductA, /Product1, etc.
Escaping wildcards in paths
If you need to use the wildcards as standard characters inside path expressions, enclose the character inside brackets ([ ]). For example:
- /Special[_]Offers - selects the Special_Offers document
Using relative paths
You can use relative paths expressions to select child documents or parent documents.
Examples:
- . - the current document’s path
- .. - the path of the current document’s parent
- ./Product - document Product under the current path
- ../Product - document Product under the parent document of the current path
- ./% - all documents under the current path (or selection of the current document, see Leaving the Path value empty below)
- ../% - all documents under the parent document of the current path
Leaving the Path value empty
If you leave the path value empty, the behavior depends on the type of the component and other variables.
Navigation components
For navigation components (such as the CSS list menu web part), an empty value always sets the path to all documents (equivalent of /%).
Standard document data sources
General web parts and controls with document data sources perform one of the following actions if you leave the Path property empty:
- Selection of the current document - the component loads and displays only the current document using the Selected item transformation (if specified).
- Loading of child documents - equivalent of <current alias path>/%. All filtering options specified for the data source still apply.
The behavior depends on the following conditions:
* Whether the listing component’s Document types (ClassNames) property includes the current document’s document type. Note: An empty value includes all document types.
** If the current document type has the Behaves as Page (menu item) type flag enabled (Document types -> Edit the document type -> General).
Document type match (*) |
Behaves as Page (menu item) type flag (**) |
Empty path behavior |
|
|
Selection of the current document |
|
|
Loading of child documents |
|
|
Loading of child documents |
|
|
The data source does not load any data at all |
For standard document data sources, the ./% path expression works exactly the same way as an empty path value.
Getting parts of the current path
You can use special expressions to extract parts of the current document’s path.
- {0} - the alias of the document on the first level of the current path
- {1} - the document alias of the current path’s second level
- …
For example, if the document path is: /Company/Careers/USA-Branch/Development/QA-Engineer
- {0} = Company
- {1} = Careers
- {3} = Development
Path examples:
- /{0}/{1}/% - all documents under the second level of the current path
- /{0}/{1}/Details - document Details on the third level of the current path
Note: If you attempt to extract a level that does not exist in the current document’s path:
- The expression returns an empty value.
- If there is a slash (/) after the expression, the system removes it when resolving the overall path.