LookUp System
Many things in the EAV and 2sxc require it to look up parameters. Examples could be:
- The current Page ID
to then find metadata for this page - The current Date to filter out news items which should be published in future
- An Id from the URL Parameters to show details about this id
This is done using Tokens which look like [QueryString:Id]
.
To achieve this 2sxc has three parts:
- Tokens which parses the placeholders
- The LookUpEngine which will get the values...
- ...using LookUp Sources to really resolve the values.
Tip
The LookUp System is used in Queries and Token Templates. But since Token-Templates are fairly trivial, we recommand that you only use Tokens for Queries and instead create your Templates using Razor.
Example Without LookUp
Imagine a Query which has an EntityId Filter which expects an ID. This could be hardwired like this:
What happens now is as follows:
- The EntityId-Filter will pass all the settings to be parsed by the LookUp-Engine
- The LookUp-Engine will detect that it's a simple value (not a Token) and just return the
38654
- The EntityId-Filter will then do it's job and retrieve this item
Example With LookUp
But it would make more sense if the ID were to be dynamic, maybe from the URL like this:
What happens now is as follows:
- The EntityId-Filter will pass all the settings to be parsed by the LookUp-Engine
- The LookUp-Engine will detect the Token and parse it
- Since the first part in the token says
QueryString
the LookUp-Engine will check if it has a LookUp-Source by that name - Since it has a LookUp which answers to
QueryString
, it will ask this source if it can resolveid
- Assuming that the page has
?id=38654
then the LookUp will say yes! it's38654
- The EntityId-Filter will then do it's job and retrieve this item
Discover More
- The Token Syntax and all the features
- LookUp Engine
- LookUp Sources
- Query LookUps
- Token Template LookUps
For example, when a Query is created, it may need to know the current PortalId or the current time, to properly filter/sort something.
This is achieved through 2 special object types, the ToSic.Eav.LookUp.ILookUp and ToSic.Eav.LookUp.ILookUpEngine, both in the ToSic.Eav.LookUp namespace.
Also Read
- LookUp Tokens Explained
- DataSource Configuration: Configuration.Parse()
- ToSic.Eav.LookUp
- ToSic.Sxc.LookUp
- ToSic.Sxc.Dnn.LookUp
History
- General Tokens introduced in 2sxc 1.0
- Most enhancements were in 2sxc 07.00