How to write a macro for WHERE condition in a repeater

Janine Fechter asked on July 28, 2016 14:43

I created a page type for News Article with a field for Department. In the News page type, the list of options for Department is a dropdown list that's pulling from a custom table.

On the News Article Page, the field name is "postDept" and the form control is "Custom Table Item Selector". The Custom Table is named "deptList" and the value column is "deptName".

I want to put a repeater on each department's respective page that will pull all news stories for that department. So if a news article ("ArticleOne") has "Alpha" selected in the "postDept" field, I want the article to display on Alpha Department's page.

I thought this could be done by putting a Macro into the WHERE condition of a repeater and placing that repeater on the department's page - but I don't know how to create that Macro. I've read the macro syntax from the documentation but am still stuck -- any help would be much appreciated!

Correct Answer

Chetan Sharma answered on July 28, 2016 16:18

Hi Janine,

No that was not obvious :) I was just clarifying the way you are accessing the field value.

In the where clause of the repeater you can use this condition to filter the documents. This is assuming that value of department is already on the page.

postDept = '{%postDept%}'

Kentico will replace value inside {%postDept%} with the value of a department for that page and filter results for you.

Let me know if it works for you

Cheers, Chetan

3 votesVote for this answer Unmark Correct answer

Recent Answers


Chetan Sharma answered on July 28, 2016 14:49

Hi Janine,

Is selected department part of a query string parameter on your page like this

`website.com/pages?postDept=AlphaOne`

Cheers Chetan

1 votesVote for this answer Mark as a Correct answer

Janine Fechter answered on July 28, 2016 15:09

Hi Chetan,

No it isn't - how would I add that into the page? Sorry if that's an obvious question that I've missed.

Janine

0 votesVote for this answer Mark as a Correct answer

Anton Grekhovodov answered on July 28, 2016 15:32 (last edited on December 10, 2019 02:30)

Hi Janine,

Try to use postDept = '{% CurrentDocument["postDept"] |(identity)GlobalAdministrator%}'

0 votesVote for this answer Mark as a Correct answer

Janine Fechter answered on July 28, 2016 16:57

Thanks Anton and Chetan for your quick responses. @Chetan yours worked perfectly for the pages - thanks again!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.