Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Hiding Web Parts on Specific Page View modes: 
User avatar
Member
Member
Armysniper89 - 1/25/2011 3:59:34 PM
   
Hiding Web Parts on Specific Page
I have a web part on my template but I want to hide it for a specific couple of sub pages but not ALL sub pages. Is there a way to accomplish this? In the Visibility section of the web part (Kentico Message Board Web Part...not my own) it only allows me to define it for Types and Roles.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/25/2011 4:14:08 PM
   
RE:Hiding Web Parts on Specific Page
Hello,

You can create a macro which would hide the webpart if it is on a specified page. A simple example would be the following:

Syntax:
{%if (macro == "something") { "write_this_if_true" } else { "write_this_if_false" }%}

Example:
{%if (cmscontext.currentpageinfo.documentname == "Home") { "false" } else { "" }%}

If you insert this example into any webpart, it's properties, visibility property, the webpart will be hidden on the document with the name Home. For more information about macros please check our documentation or our CTO's blog.

Best regards,
Boris Pocatko

User avatar
Member
Member
Armysniper89 - 1/25/2011 5:00:10 PM
   
RE:Hiding Web Parts on Specific Page
Totally forgot about those! Shows you what happens when you stop using the product for a month. ;) Problem is when I entered the macro like this:
{%if (cmscontext.currentpageinfo.documentname == "About Us") { "false" } else { "true" }%}


It did not work. Ideas? It tried with and without quotes around About Us.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/26/2011 3:57:14 AM
   
RE:Hiding Web Parts on Specific Page
Hello,

You can try the "|(contains)<string> - True if value contains given string" instead of the "|(equals)<string>" syntax without the "space_Us" string:
{%if (Contains(cmscontext.currentpageinfo.documentname, "About")) { "false" } else { "true" }%}

I would also recommend you to test the macro on some other webpart to see if it resolves correctly to true/false.

Best regards,
Boris Pocatko

User avatar
Member
Member
Armysniper89 - 1/27/2011 12:18:22 PM
   
RE:Hiding Web Parts on Specific Page
The web part I am testing this on is a built in Kentico Message Board web part. It wont change no matter what I type in. I have an "About Us" and a "Terms of Use" page that I do not want this visible on. No matter what I do with this macro, it always shows up.

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 1/28/2011 4:09:29 PM
   
RE:Hiding Web Parts on Specific Page
Hello,

I've inserted the same macro into a webpart and changed the "About" string to "News" and it works just fine (it is hidden on a page called News). Please see the attached screenshot for more information. Could you please also apply the latest hotfix for your version and see if it helps?

User image

Best regards,
Boris Pocatko

User avatar
Member
Member
Armysniper89 - 1/28/2011 4:44:57 PM
   
RE:Hiding Web Parts on Specific Page
I already have the latest hotfix available. I guess I am going to have to open this as a support request.

User avatar
Member
Member
perezj-gmail - 7/1/2011 11:03:56 PM
   
RE:Hiding Web Parts on Specific Page using Custom Macro
I am having trouble with hidden a webpart when using a custom macro

I have a custom macro {% ProcessCustomMacro("IsNotDefault", "") %} which the results is "true" or "false"

in the CMCustom.cs:
case "IsNotDefault":
match = true;
if(!GetCurrentCenterProfile().GetValue("CenterNumber").ToString().Equals("000")){
result = "true";
}else{
result = "false";
}

I have tried
{%{#IsNotDefault#}|(equals)true%} and others.

I see a lot of documentation when using built in macros such as the document name etc

Can someone provide and example when using a custom macro when calling ResolveCustomMacro??

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 7/2/2011 6:44:45 AM
   
RE:Hiding Web Parts on Specific Page using Custom Macro
Hello,

As you can see in the CMSCustom.cs file there is a switch which uses the ToLower() method:
        switch (expression.ToLower())
{
....
}

Which means that your macro "IsNotDefault" will never be matched because everything gets converted to lowercase. Please rewrite your code from:

case "IsNotDefault":

to

case "isnotdefault":

And check if this helps.

Best regards,
Boris Pocatko