Blog Transformation using Macros not ASCX

Hatton Point asked on January 21, 2015 22:27

I'd like to convert a blog transformation currently in ASCX to Text/XML in order to use Macro more efficiently. However, I'm unsure whether it is possible to do so when needing to reference an API method. Take the Corporate Site Demo code for example:

<div class="blogPostDetail">
    <h1 class="black"><%# Eval("BlogPostTitle", true) %></h1>
    <div class="bold"><%# Eval("BlogPostSummary") %></div>
    <span class="black bold"><%# BlogFunctions.GetUserFullName(Eval("NodeOwner")) %>  </span>
    <%# BlogFunctions.GetBlogCommentsCount(Eval("DocumentID"),Eval("NodeAliasPath")) %> comments</a><br />
    <%# IfEmpty(Eval("DocumentTags"),"","Filed under: " + BlogFunctions.GetDocumentTags(Eval("DocumentTagGroupID"), Eval("DocumentTags"), "~/Community/Blogs/Andrew-Jones-Blog.aspx")) %>
</div>

The method "BlogFunctions.GetDocumentTags" does not appear to work, returning an error about parameters being incorrect. I referenced the API documentation, but did not find an alternative method. Is it possible to still call API methods from Text/XML transformations or are you forced to use ASCX for transformations requiring API calls?

Correct Answer

Jim Spillane answered on January 22, 2015 02:24

Give this conversion a try...

<div class="blogPostDetail">
  <h1 class="black">{% BlogPostTitle"%}</h1>
  <div class="bold">{% BlogPostSummary %}</div>
  <p>{% IfEmpty(BlogPostTeaser, "<img src=\"~/App_Themes/CorporateSite/Images/no_image.png\" alt=\"Default blog teaser image\" />",GetImage("BlogPostTeaser", 230)) |(identity)GlobalAdministrator%}
</div>
1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on January 21, 2015 23:42

You can use macros within ascx transformations. What macros are you looking to use? Or what are you trying to achieve?

0 votesVote for this answer Mark as a Correct answer

Hatton Point answered on January 22, 2015 00:35

Yes, I can use macros via ResolveMacros() method, but the preference is standardize development on Macro syntax and Text/XML. If API methods cannot be called from Text/XML however then we won't be able to convert 100% of the transformations.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on January 22, 2015 02:21

You are correct, how will that standardize development on Macro syntax?

Technically you can't have a macro without C# code behind. Whenever I create macros, I also create custom transformation methods so those same methods that I made available in the macro engine, are also available in transformations.

I don't mind text/xml transformations but you don't get the power behind them as you would if you had an ascx transformation. For instance, I'm just finishing upgrading a site from 6.x to 8.2 and they are using aspx mode. I checked out all the transformations after the upgrade, fixed the issues I knew of then built the project with those ascx transformations checked out. I was able to then find other custom code that had been written and resolved it. You can't build a text file.

Using the ResolveMacros() method will build in an ascx transformation as well as any custom transformation methods you create. Macros will not.

2 votesVote for this answer Mark as a Correct answer

Hatton Point answered on January 22, 2015 03:11 (last edited on January 22, 2015 03:11)

Thanks Brenden for the suggestions. Jim's answer more accurately answers my question of wanting to use Macros. The answer is also quite simple, I wish there was more documentation around how Transformation methods change between Macro and ASCX modes, i.e. removing the "BlogFunctions" class from before the method, as I continue to find quirks/differences between how Macro and ASCX methods are called.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on January 22, 2015 05:55

Not a problem Hatton. Jim provides a great solution. I was simply stating I choose ascx because it's robust and can be built/validated whereas text/xml cannot and the fact that you have to write the C# code already to get your macro to work. From a speed standpoint, there is no difference between the two from what Kentico has told me.

Good luck!

0 votesVote for this answer Mark as a Correct answer

Jim Spillane answered on January 27, 2015 04:36 (last edited on January 27, 2015 04:37)

This is worth repeating from Brenden above...

Whenever I create macros, I also create custom transformation methods so those same methods that I made available in the macro engine, are also available in transformations.

1 votesVote for this answer Mark as a Correct answer

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