It is quite a common situation when you need to create a data source query for a field in a template that is quite complex: e.g you would like to use the current item property as a part of a query or you have a dependency on some other item in a content tree.
In the case of list fields, you could use GetLookupSourceItems pipelines to modify query according to your requirements.
public class DataSourceTokens
public void Process(GetLookupSourceItemsArgs args)
// Custom code to get value of dependency
var dependency = "some value";
// set default values for tokens
var token = dependency ?? "."
// replace tokens in datasource of the field
args.Source = args.Source
As usual, you will need to register this pipeline in the Sitecore patch file and put it in /app_config/include
Finally, to use it need to use the defined token in a field query, when you defining your template.
Simple, but give you a lot of flexibility.