Posted on 10/09/2021 14:57:10
Hi Nicolai,
Extensibility point
My extensibility point is for Repository's Code Providers (used in Query expressions). My code is mostly from https://doc.dynamicweb.com/training/t3-platform-developer/t3-platform-developer/3-5-extending-indexing#sideNavTitle1-2-2.
Debugger
I attached the debugger to confirm what I had available to me in the base class, but I only have access to the Code Provider's parameters, and what I needed was the current context of the Query (getting the value of a parameter).
What am I trying to achieve
This has happened to me twice already. We need to add a Code Provider (query expression) that only triggers when a certain condition is met. For example, the expression could be:
ProductId IN "Custom list of Product Ids"
However the custom list cannot be triggered every time, so we started by doing something like this
public override string BuildCodeString()
{
if (string.IsNullOrEmpty(QuerystringParameter)
|| Dynamicweb.Context.Current.Request.QueryString[QuerystringParameter]?.ToLower() != "true")
{
return null;
}
var productIds = GetCustomListOfProducts();
return string.Join(",", productIds);
}
This works great, meaning that the expression is disregarded if the QuerystringParameter is not in the querystring.
My final step was to change it from a Querystring parameter to a (Repository) Query parameter
Then on a Paragraph I can override the default value of "MyCustomParameter" and that would trigger the expression - This is what I can't get to work easily (without the workaround at least)
Workaround
- I believe I found a workaround. I can get the current page (not the current paragraph), so from it, I can get the page's paragraphs that contain the Product Catalogue/Query Publisher App, and get the values defined in the paragaph module settings.
OR
- Customize the feed request and ensure that "MyCustomParameter" is submitted as a querystring parameter, but my goal was to conditionally trigger an expression without customization on the templates (only UI settings).
The ability to conditionally trigger expressions if a query parameter = X has come up a few times now. Maybe in the future there would be a nicer way to do this, but for now as long as I can get this to work I'm good.
I hope this makes sense.
Best Regards,
Nuno Aguiar