Resolve macro in Text field on Form tab

Adam Steffes asked on December 31, 2014 18:01

I'm attempting to resolve the following macro for a URL on the form tab in a text field: {%CurrentDocument.Currenturl%}

However, the macro doesn't resolve, but instead outputs the macro signature and hash: <a href="{%CurrentDocument.Currenturl|(user)|(hash)48d86e9c677f408ae6b2838deeeb6ba60ef9727fab6cee4b23df7926f0393952%}" class="view-more">asdf</a>

How can I get Kentico to resolve this macro in this context? Or, is it not possible?

Recent Answers

Brenden Kehren answered on January 1, 2015 00:51

Your macro is signed, you need to save it slightly different to make it not signed: {%CurrentDocument.NodeAliasPath@%} Putting the @ symbol before the closing curly brace will not sign the macro and should resolve your problem.

0 votesVote for this answer Mark as a Correct answer

Adam Steffes answered on January 1, 2015 15:38

Unfortunately {%CurrentDocument.NodeAliasPath@%} just produces {%CurrentDocument.NodeAliasPath@%} as HTML directly.

If I remove the '@', it displayes the macro w/ the hash as above.

Kentico doesn't seem to want to evaluate these macros in this context. Is there anything wrong with inserting macros into the form fields in Kentico? Are macros just not allowed there?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on January 1, 2015 16:21

Ahh I see where you're entering that now, sorry for the confusion Adam.

You wouldn't want to have the user enter a macro every time they create a new item. So the place I'd first look to would be the default value of that field when you define your page type, biz form, etc. BUT I happen to remember this does not work as expected because of the page life cycle. So I ended up creating a custom event handler (roughly 10 lines of code or so) to set a default for the field(s) needed when inserting or updating.

Nice part about the custom handler is they are centrally located so no need to search around all of the different forms or fields. Bad part is it's "custom" server coding...

1 votesVote for this answer Mark as a Correct answer

Adam Steffes answered on January 1, 2015 18:27 (last edited on December 10, 2019 02:30)

Hey Brenden,

Thanks for your help on this topic (and all the other ones, too).

I maybe should have indicated this earlier, but the result I'm going for is the ability for an advanced content editor to populate these form fields with Macros, specifically concatenating a hyperlink with a macro - such as "http://someadvertisingsite/useremail={%CurrentUser.Email|(identity)GlobalAdministrator%}"

It doesn't sound like this is going to be possible in the Form tab context from what you're saying.

I wish that there was documentation that indicated where Macros are usable and where they are not in Kentico.

1 votesVote for this answer Mark as a Correct answer

Sandro Jankovic answered on January 2, 2015 13:46

Hi Adam,

As Brenden mentioned, using the macro in this way will probably not work as you expect it to. However, if you could clarify how you are later using/loading the information saved on the Form tab we may have some suggestions. You are probably displaying this information to a user on the live site, and would want his e-mail to be included as a part of the link - in that case you could use the macro in the transformation and have the content editors just set the first part of the link. More details about what you are trying to implement would help us provide more accurate suggestions (and code samples).

Also, we do have some documentation on where macros can be used but unfortunately it does not cover all potential options. We are constantly working on expanding and improving our documentation and hopefully this will be a part of the upcoming improvements.

Best Regards,


0 votesVote for this answer Mark as a Correct answer

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