Order Transformations

Carson Wong asked on July 12, 2016 17:39

Hi,

I have the following code in a transformation:

<%@ Import Namespace="CMS.MacroEngine" %>
<%@ Import Namespace="CMS.Membership" %>
<%

MacroContext.GlobalResolver.SetNamedSourceData("FOO", "201");
%>

Basically, I want a global variable to be used in other transformations within that page. The problem is, this transformation is called after the other transformations, so the other transformations sees this variable as empty.

How can I order transformations? By the way, my transformations are in different Viewers/Repeaters, because I have several data sources.

Correct Answer

Trevor Fayas answered on July 12, 2016 18:28

By default the web parts render first to last in their order on the page. If you are trying to set a Named Data Source, you should probably do it through either the Page Template's Layout, a Custom Control, etc that uses the OnInit

<script runat="server">
protected override void OnInit(EventArgs e)
{
  base.OnInit(e);
  MacroContext.GlobalResolver.SetNamedSourceData("FOO", "201");
}
</script>

Be warned though, the Global Resolver is GLOBAL, means every visitor shares this. You may want to use the CurrentResolver vs. the GlobalResolver, the CurrentResolver is user specific, this caused some headaches when i used the wrong one becuase a user visiting a page could get someone else's macro settings if the other person visited near the same time.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Carson Wong answered on July 12, 2016 19:27

Thank you for your help!

0 votesVote for this answer Mark as a Correct answer

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