Developer forum

Forum » Templates » RenderItem filter AND and OR conditions

RenderItem filter AND and OR conditions

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,m

This is a copy of the a comment from one of my coleagues. It was posted on another thread and got no answers so far. I thought that it will help if I make it a thread on its own.

The context.

I have some Dw_Page items that I want to list based on the following criteria:

 
string filterValue2= "Item.Tip='Articole'";
filterValue2 =  filterValue2 + " and " + "Item.Id !='" + mainArticleID +"'" + " and " + "Item.Id !='" + secondaryArticleID +"'" + " and " + "Item.Id !='" + thirdArticleID +"'"  + " and " ;
string  filterValue6 =  "Item.SectiuneParinteId ='" + GetString("DwPageID")+ "'";
string  filterValue7 =  "Item.SectiuneSecundara ='" + GetString("DwPageID")+ "'";
filterValue2 =   "("+ filterValue2 + filterValue6 + ")" + " or " + "(" + filterValue2 + filterValue7 + ")"  ;
 
if I print filterValue2 it shows me :
Item.Tip='Articole' and Item.Id !='14760' and Item.Id !='14757' and Item.Id !='14756' and Item.SectiuneParinteId ='17' or Item.Tip='Articole' and Item.Id !='14760' and Item.Id !='14757' and Item.Id !='14756' and Item.SectiuneSecundara ='17'
 
 
The result seems to be correct besides the fact that the filter does not really work. Any ideas on how to make that "or " to work by grouping the filter properties using brackets?
 
Thank you,
Adrian
 

Replies

 
Nicolai Pedersen
Reply

Nope - hard to tell without debugging.

I would really suggest that you use the index and querypublisher for something this advanced.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

I would use QueryPublisher but I cannot (or don't know how to) call the query publisher in the template. i can only use it in a paragraph and in this current situation is not applicable.

What I would use is a best practice on how to build the filter (the syntax) in case of combined conditions. I would normally use parenthesis to group different conditions but it seems that in this case they are ignored.

What I need to build as filter looks something like this:

string Filter = 'Field1 = Value1 and (Field2 = Value2 Or Field2 = Value3)';

Field1=Value1 works.

Field2=Value2 Or Field2=Value3 works

Field1=Value1 and Field2=Value3 works

The only statement that does not work is the combined one.

If you can provide an example, I can go with it. I know I have asked similar things before, in other posts, but the documentation for the usage is still incomplete.

Thanks,

Adrian

 
Nicolai Pedersen
Reply

Short answer: I am not sure you can do that with this. I cannot understand why you cannot use the querypublisher...

Anyways - you are also welcome to take a look at the source code in the item publisher and see if that makes better sense.

It might be a better idea to do some calculated values that makes your filters more simple. This feature is meant for simple filtering and not complicated queries. We have data lists and querypublisher for that.

BR Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you for your reply.

The whole logic is inside the template code, not in the paragraphs. I agree QueryPublisher would have been the best option But until we can call it directly form the template, I cannot use it in this case.

The purpose for this is that we need to list all articles that are o type 'Articol' and PrimarySection is {PageID} or SecondarySection is {PageID} where PageID is the ID of the page you are visiting.

The project is Content heavy and we had to improvise a lot in order to make the content available for edit in a fashionable manner.

In the ItemPublisher interface I see there is no way to group the condtions. So I guess it has not been implemented.

I will have a look in the source code to see if I can find a solution.

Otherwise we'll probably load it with Ajax using QueryPublisher.

Thanks,
Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

I got back to this issue since I am still encountering some problems rendering the content.

Can you advise on how I can include QueryPublisher directly in the template? Without using a paragraph?

I am using DW 9.6.x

Thank you,

Adrian

 
Nicolai Pedersen
Reply

As I said earlier, I am not sure you can. You can use the Indexing API directly - but I have no examples, except the source code of the querypublisher.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Understood.

I thought there might be something similar to RenderItemList.

I will look in the API and find a solution to use it directly in the template.

Thank you very much,

Adrian

 

You must be logged in to post in the forum