Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Macro in where Condition (CurrentUser.IsInRole) View modes: 
User avatar
Member
Member
lwhittemore-emh - 5/8/2013 2:03:46 PM
   
Macro in where Condition (CurrentUser.IsInRole)
I am trying to write a macro in my where condition of a repeater that checks to see if a user is in a particular role.

This is what I am trying:
{%if (CurrentUser.IsInRole("Collaborative") == "True") { " Blah Blah Blah" } else { "something differnet" }%}

So I am not sure why the first statement doesnt work. It looks like the first part should resolve the True and then that would equal True and then yeild the truevale string... (hope that made sense) but it is not doing it.

User avatar
Member
Member
kentico_edwardh - 5/8/2013 2:30:19 PM
   
RE:Macro in where Condition (CurrentUser.IsInRole)
Hello,

Please try using K# syntax to create this macro with IF statement where you will check the current user roles: devnet.kentico.com/docs/6_0/devguide/index.html?ksharp_syntax.htm e.g.:

{% if (CurrentUser.IsInRole("Collaborative")) {"User is in Role"} else {"Not in role"} %}

Best Regards,
Edward Hillard

User avatar
Member
Member
lwhittemore-emh - 5/8/2013 2:49:04 PM
   
RE:Macro in where Condition (CurrentUser.IsInRole)
Awesome. We're almost there. However it doesn't seem to work in the "Where Condition" field. If I put it in the html before or after it works but in the where condition I get nothing.

User avatar
Member
Member
lwhittemore-emh - 5/8/2013 3:09:24 PM
   
RE:Macro in where Condition (CurrentUser.IsInRole)
{% if (CurrentUser.IsInRole("Collaborative")) {"Security = 'Collaborative'"} %} This is what I have in the where condition. When I have This "Security = 'Collaborative'" excluding the outer quotes I get the result I want. With it within the K# code it does't seem to work. When I have the K# in the before HTML box it does seem to work and I get what is in the double quotes.

User avatar
Member
Member
kentico_edwardh - 5/9/2013 11:43:52 AM
   
RE:Macro in where Condition (CurrentUser.IsInRole)
Hello,
As you can see from the code below:

// Replace apostrophe
input = input.Replace("'", "''");


we are replacing the apostrophe character within the Where Condition in order to prevent SQL injection. You can turn off this functionality either globally, or for this web part by following the example at the bottom of this page: http://devnet.kentico.com/docs/7_0/devguide/entering_macro_expressions.htm

Best Regards,
Edward Hillard