CoolMonster
CoolMonster

Reputation: 2267

CMSRepeater Condition based on current Document Categories in Kentico

I have a section in My Template Its has to Show the Upcoming Events in SideBar.

Scenario:

1.Events Document Where Place as Child in Root\Events..

2.Events will be assigned to the Specific Categories.

3.Document Which want to show those Events will also assign that particular Category

Now the CmsRepeater has to pull the Event base on the Current Document Categories.

I have some alternative to do this buy using the related Doument functionality.. But its tedious job to assing A single Event to all pages it want to show.

Upvotes: 0

Views: 1121

Answers (2)

If you want to exclude the current document from the repeater I will include something like this:

DocumentID != {% CurrentDocument.ID #%}

so, the final query will look like the following:

DocumentID != {% CurrentDocument.ID #%} AND DocumentID IN (SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID IN {% val = "("; foreach(category in CurrentDocument.Categories) { val += category.CategoryId + "," }; val = val.TrimEnd(",")+")"; return val; #%})

Upvotes: 0

mivra
mivra

Reputation: 1400

If I understand you correctly you are trying to display documents which have the same categories as the current document. Then you could use macros with combination with WHERE condition.

This macro iterates through categories of current document and creates a string which can then be used as part of where condition.

{% val = "("; foreach(category in CurrentDocument.Categories) { val += category.CategoryId + "," }; val = val.TrimEnd(",")+")"; return val; #%}

Then put something like this into repeater's where condition field.

DocumentID IN (SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID IN {% val = "("; foreach(category in CurrentDocument.Categories) { val += category.CategoryId + "," }; val = val.TrimEnd(",")+")"; return val; #%})

It may yet need some refinement for edge cases but it should represent the basic idea.

Upvotes: 1

Related Questions