Place macro in default value

Tom Barker asked on February 10, 2017 14:55

Hi,

I want to include a macro in a default value for a webpart, but I don't want it to be resolved, I want the literal text for the macro, as it's a macro the web part it's self with resolve.

The default value in question is: Appointment Date: {% bookingdate %}<br /> Appointment Time: {% bookingtime %}

I haven't checked the "Resolve default value" but it still seems to be stripping it, anyone know how I can achieve this?

Thanks, Jack

Recent Answers


Trevor Fayas answered on February 10, 2017 15:21

What you can do, as somewhat annoying as it is, is use a macro to output a macro

{% "{% bookingdate %}" %}

It should render and just output the text. Try that, if it doesn't work, and you're going for output, you can try breaking it aparent with a span.

{<span/>% bookingdate %<span/>}

The spans should not show anything in HTML but will prevent the macro from detecting.

0 votesVote for this answer Mark as a Correct answer

Tom Barker answered on February 10, 2017 15:53

Hi Trevor,

Thanks for your suggestion, unfortunately {% "{% bookingdate %}" %} appears to just render " %}

I don't think I can use the {<span/>% bookingdate %<span/>} because I want the macro to resolve in the actual webpart.

Thanks, Jack

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on February 10, 2017 16:47 (last edited on February 10, 2017 17:01)

Okay i think i'm following you now. When you set a macro in the "Default Value" of the webpart configuration itself, it's rendering the macro vs. putting that macro as the value when you place it on the page. I gotcha now.

I'm trying a bunch of different things...thus far no luck. May need to create a custom macro method that just spits out the value with the {% and %} around it...

Just an update, tried using .net Code to resolve the macro {% "{% Test %}" %} with the Macro settings to not do recursive resolving...but that didn't work. Still trying to find a work around for ya.

0 votesVote for this answer Mark as a Correct answer

Tom Barker answered on February 10, 2017 16:49

Hi Trevor,

Thanks again, the custom web part outputting the contents sounds promising, I'll give that a try and report back

Thanks, Jack

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on February 10, 2017 17:06 (last edited on December 10, 2019 02:30)

Definitely give it a try, look up in documentation how to create Custom Macro Methods, then in the macro method take the value, and just return "{% " + TheValue + " %}" and see if that works...

Note the only potential issue is you may (depending on what the macro does) need Security # included, otherwise use @, but then again it may just add that for you after you hit the "Save" on your web part.

ALso, try in the "Default Value" when you do this to also ad |(recursive)false, just in case

{% Custom.RenderMyMacro("bookingdate") |(recursive)false |(identity)GlobalAdministrator%}

0 votesVote for this answer Mark as a Correct answer

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