How to display macros as content (without resolving them)

Stefan Lorenz asked on July 10, 2014 06:03

Hi,

I'd like to show macro expressions as text (like in the docs). Anyone knows a simple way to achieve this without disabling macro resolving for the whole page? Right now I manually html-encode %, but I thought there must be a more elegant solution...

Recent Answers


Yehuda Lando answered on July 10, 2014 12:23

I didn't try, but maybe it's like format strings, where you escape using {{ (like {{% DocumentName %%}}?

0 votesVote for this answer Mark as a Correct answer

Stefan Lorenz answered on July 14, 2014 14:34

Unfortunately that doesn't work. And my initial workaround is a bad one because ckEditor resolves the encoding when re-editing the page.

0 votesVote for this answer Mark as a Correct answer

Stefan Lorenz answered on July 15, 2014 16:39

Ok, as a workaround I'm fighting fire with fire:

[MacroMethod(typeof(string), "Prints a macro as text", 1)]
[MacroMethodParam(0, "Macro text", typeof(string), "the macro without {% %}")]
public static object PrintMacro(EvaluationContext context, params object[] parameters)
{
    switch (parameters.Length)
    {
        case 1:
            return "{% " + parameters[0].ToString() + " &#37}";
        default:
            return "";
    }
}

This works at least, but if anyone knows a better solution, please share...

0 votesVote for this answer Mark as a Correct answer

Martin Danko answered on August 1, 2014 10:54

Hello Stefan,

you can write a macros with an extra space character, so instead of: {% DocumentName %}

you will write: { % DocumentName % }

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

Stefan Lorenz answered on August 1, 2014 10:58

Yes, but then the extra space would be displayed.

0 votesVote for this answer Mark as a Correct answer

Martin Danko answered on August 1, 2014 11:07 (last edited on August 1, 2014 11:07)

Hi Stefan,

You're right but that's the easiest way from my point of view, you can write e.g. a note at the bottom that user should remove extra spaces.. this is also the "workaround" we are using when publishing articles on the DevNet.

Best regards, Martin

0 votesVote for this answer Mark as a Correct answer

Stefan Lorenz answered on August 1, 2014 11:26

Well, in the docs (e.g. https://docs.kentico.com/display/K8/Macro+syntax) I don't see that extra space, so at least there you're using another way (or the docs aren't part of a Kentico site).

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on August 1, 2014 13:39

Hi Stefan,

The documentation is not running on Kentico site. We are using special tool for documentation :-)

0 votesVote for this answer Mark as a Correct answer

Jaroslav Kupcik answered on September 19, 2014 13:05

Hello,

For displaying macro without resolving, you can try to use the html entity % instead of '%' character. It worked for me.

1 votesVote for this answer Mark as a Correct answer

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