Resolve macro on WhereConditon attribute

Varinder Singh asked on June 12, 2014 00:29

Hi Fellas,

I am trying to approach developing webparts/templates in a slightly different way:

  • export all templates to CMSVirtualFiles
  • use visual studio to drag and drop webparts instead of using design tab of portal page

Below example might help explain the issue:

So, I've got a template called Website.SomethingAwesome.ascx

To show all items of a certain document type Website.DocumentType I go ahead and add a repeater and the code looks something like below:

<cms:CMSRepeater WhereCondition="NodeAlias LIKE 'awesome'" ID="CMSRepeater1" TransformationName="Website.DocumentType.Item" Path="/%" ClassNames="Website.DocumentType" runat="server"></cms:CMSRepeater>

Above works fine, and i get a list of items whose nodealias matches 'awesome'.

But, it seem to fail when i try to replace 'awesome' with a macro. Like below:

<cms:CMSRepeater WhereCondition="NodeAlias LIKE '{?NodeAlias?}'" ID="CMSRepeater1" TransformationName="Website.DocumentType.Item" Path="/%" ClassNames="Website.DocumentType" runat="server"></cms:CMSRepeater>

Heres the ugly way of getting around it:

    <script runat="server">
        protected void CMSRepeater1_Init(object sender, EventArgs e)
        {
            CMSRepeater1.WhereCondition = "NodeAlias LIKE '" + CMSContext.CurrentResolver.ResolveMacros("{?NodeAlias?}") + "'";
            CMSRepeater1.ReloadData(true);
        }
    </script>

and binding above event to onInit of CMSRepeater1 like below:

<cms:CMSRepeater OnInit="CMSRepeater1_Init" ID="CMSRepeater1" TransformationName="Website.DocumentType.Item" Path="/%" ClassNames="Website.DocumentType" runat="server"></cms:CMSRepeater>

Too much typing for little rewards.

On fooling around a bit on kentico's repeater popup window (the one that comes up when you try to add a webpart inside a zone in design tab) it has a checkbox field called "Disable macros:" (under performance section) which makes me wonder there must be a boolean "resolve macros" property or something on the repeater webpart that is set to true by default. Looked at the code behind of repeater control ( cmsrepeater.ascx.cs ) which is inheriting stuff from abstract class (CMSAbstractWebPart.cs) which has a property called mDisableMacros

So, the question: Why would <cms:CMSRepeater> not resolve macros? If it is something to with mDisableMacros property which i accidentally found, then, is there a way to enable macro resolving shenanigans on every web part? I mean, like everything, like, yea.. everything, i mean - well, you get the idea :)

Cookies for everyone if above is possible!*

On a different note: omg, amazing editor window!! you fellas are awesome!

*lying about the cookies btw.

Recent Answers


Joshua Adams answered on June 12, 2014 14:49

What is wrong with setting the where clause in the code behind?

0 votesVote for this answer Mark as a Correct answer

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