ASPX templates
Version 7.x > ASPX templates > K# Macros View modes: 
User avatar
Member
Member
robert-tailor.co - 3/3/2013 10:47:41 PM
   
K# Macros
I'm using v7.0.19.

K# Macros are supposed to be used anywhere you can insert text, right? And Kentico is supposed to be able to resolve them, right?

So why is it, when I insert the following K# Macro into a text box under the 'Form' tab of a given page, it is not interpreted, and instead printed literally?
{%CMS.CMSHelper.CMSContext.CurrentSite.DisplayName%}

I am using an ASPX template page with the following code to display the value of that field:
<cms:CMSDocumentValue ID="CMSDocumentValueTitle" runat="server" AttributeName="DocumentName" />

Thanks!

User avatar
Kentico Support
Kentico Support
kentico_janh - 3/5/2013 4:23:55 AM
   
RE:K# Macros
Hello,

No, macros are not resolved automatically. However if you place them directly to some text area in editing mode (editable region, static text, text areas on master pages, etc.) those macros are resolved. You can test it and place for example the Static text web part on your document and place there your macro directly:
{%CurrentSite.DisplayName%}

Or you can call the CMS.CMSHelper.CMSContext.CurrentResolver.ResolveMacros(string inputText) method to resolve filled macro.

Best regards,
Jan Hermann

User avatar
Member
Member
robert-tailor.co - 3/5/2013 2:12:40 PM
   
RE:K# Macros
kentico_janh wrote: Hello,

No, macros are not resolved automatically.

From your own documentation (http://devnet.kentico.com/docs/devguide/macro_expressions_overview.htm):

Macros are strings that are automatically resolved into their value equivalents.

Given how patchy the support for K# Macros is in Kentico, I think it'd be really helpful if your documentation either:

1. Listed the places where K# Macros can't be used.

Or, if that list is too long,

2. Listed the places where K# Macros can be used.

And also, for areas where K# Macros can't be used, your documentation should explain the alternative methods described in your post.

User avatar
Kentico Support
Kentico Support
kentico_janh - 3/7/2013 5:27:17 AM
   
RE:K# Macros
Hello,

I have asked our development department and regrettably there is no list of places where macros are or are not resolved automatically. In most of common locations within the Kentico administration (except ASCX transformations and ASCX layouts) macros are resolved automatically. I have checked our documentation for macros and there is a section called Resolving macros using API where is described the method mentioned in my last post. I am sorry for this inconvenience, but where a macro is not resolved automatically, you need to resolve it manually using that method.

Best regards,
Jan Hermann