Conditional Macro

Wei Wang asked on July 7, 2021 14:38

Hi,

I try to use a conditional macro (if... else) to achieve the purpose of displaying different dashboard based on different username. The expression in the If is an iframe kind of javascript. But I cannot get this to work. Is there a way to make this kind of expression work using the conditional macro?

Here is the macro I wrote: {% If(CurrentUser.UserName == "xxx") { "<script type='text/javascript' src='https://xxx.xxx.net/javascripts/api/viz_v1.js'><div class='tableauPlaceholder' style='width: 270px; height: 227px;'>" } else {"No"} #%}

This is for Kentico 9 portal engine.

Thanks, Wei Wang

Correct Answer

Juraj Ondrus answered on July 8, 2021 11:53

And I would maybe use open conditions and loops. There could be clash double quotes vs. apostrophes vs. single quote in the HTML code.
{% If(CurrentUser.UserName == "xxx") { %} your JS script code or other text {% } else {"No"} %}

0 votesVote for this answer Unmark Correct answer

Recent Answers


Wei Wang answered on July 7, 2021 14:41

<script type='text/javascript' src='https://xxx.xxx.net/javascripts/api/viz_v1.js'><div class='tableauPlaceholder' style='width: 270px; height: 227px;'>

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on July 7, 2021 15:17

I'd debug your macro. You can test it in the System > Macro > Console area and verify what is coming back in the CurrentUser object. Then type out a simple macro condition and see if it returns what you're expecting and work with that. If it doesn't work when you add it back to the webpart then, turn on debugging for the site and see what value is being returned.

0 votesVote for this answer Mark as a Correct answer

Wei Wang answered on July 8, 2021 13:37

thank you all

0 votesVote for this answer Mark as a Correct answer

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