Resolving macros inside transformation with parameters

Adam Steffes asked on October 28, 2014 16:49

I'm having trouble resolving a macro inside of a nested repeater, and I'm running into some interesting behavior.

My objective is to determine the appropriate "WhereCondition" for a nested repeater by resolving a macro with the given context:

<cms:queryrepeater CacheMinutes="0" id="repShopCategory" runat="server" WhereCondition='<%# CMS.MacroEngine.MacroResolver.Resolve("{% GenerateWhereCondition(path, SKUManufacturerID)%}") %>' TransformationName ="RG.Product.xProductListforCategory" QueryName="RG.Product.qProductBasedOnManufacturer" />

Here's my custom macro setup to test this out:

[MacroMethod(typeof(string), "Generate Where Conditions", 2)] [MacroMethodParam(0, "NodeAliasPath", typeof(string), "NodeAliasPath")] [MacroMethodParam(1, "ManufacturerID", typeof(int), "ManufacturerID")] public static string GenerateWhereCondition(EvaluationContext context, params object[] parameters) { return string.Format("view_CMS_TREE_JOINED.NodeAliasPath Like '%{0}%' and view_CMS_TREE_JOINED.SKUManufacturerID ={1}", ValidationHelper.GetString(parameters[0],string.Empty), ValidationHelper.GetInteger(parameters[1], 0)); }

I've noticed some interesting behavior while trying several variations calling this custom macro. For example, the parameter "path" seems to resolve, but the SKUManufacturerID just resolves to NULL when passed in. Additionally, I've attempted to use the repeater's <%#Eval("ManufacturerID")%> in place of the parameters in several ways, but it always resolves to NULL when the parameter reaches the server side.

Seems like I'm missing a fundamental understanding of the process that's going on here, and maybe this isn't something that I can do. If you have any tips on what I can do to successfully pass these parameters through to a custom macro, please let me know.

Thanks in advance.

Recent Answers


Brenden Kehren answered on October 28, 2014 20:34

Adam,

Why try to render/resolve a macro? If you're macro method is calling a standard C# method, just call that regular C# method (namespace and all) or create a transformation method and pass the values you need, no need to complicate it with resolving a macro.

Brenden

0 votesVote for this answer Mark as a Correct answer

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