Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Showing fallback web part View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
Erik - 3/13/2013 3:33:44 PM
   
Showing fallback web part
On my template, I want to show a 'fallback' web part if a property on a particular document is empty.

In the web part properties, under 'Visible', I put the following macro:
{(1)%{(2)%CurrentDocument.LeftColumn%(2)}|(default)empty|(equals)empty|(falsevalue)FALSE|(truevalue)TRUE#%(1)}

However, the web part always shows. It doesn't hide when there is text in the 'LeftColumn' property of my document.

Any ideas?

Thanks,
Erik

User avatar
Certified Developer 13
Certified Developer 13
kentico-jx2tech - 3/13/2013 3:58:26 PM
   
RE:Showing fallback web part
try something like...
{% CurrentDocument.LeftColumn.ToString().Length==0 %}

User avatar
Certified Developer v7
Certified  Developer v7
Erik - 3/13/2013 4:04:10 PM
   
RE:Showing fallback web part
That doesn't appear to be working either :(

User avatar
Member
Member
eagleag - 3/13/2013 4:18:02 PM
   
RE:Showing fallback web part
if you put this macro in the content before (or any place it will appear on the page)
{% CurrentDocument.LeftColumn.ToString() %} do you see the content entered in that field?

User avatar
Certified Developer v7
Certified  Developer v7
Erik - 3/13/2013 4:19:10 PM
   
RE:Showing fallback web part
Yes

User avatar
Member
Member
eagleag - 3/13/2013 4:30:41 PM
   
RE:Showing fallback web part
try this:
{%
if(CurrentDocument.LeftColumn.ToString() == "")
{
return "True";

}else{

return "False";
}
%}

If it doesn't work please check what the default value of "LeftColumn" is. Is it empty string or null?

Can try this IF statement:
if(CurrentDocument.LeftColumn.ToString()  == "" || CurrentDocument.LeftColumn ==  null )

User avatar
Certified Developer v7
Certified  Developer v7
Erik - 3/14/2013 11:19:07 AM
   
RE:Showing fallback web part
{%
if(CurrentDocument.LeftColumn.ToString() == "")
{
return "True";

}else{

return "False";
}
%}


Worked, thanks! I didn't know you could write a conditional statement in a macro like that.

I think between that other conditional format and nested macros, Kentico probably wasn't parsing it correctly. (e.g. I noticed another problem having a semicolon in a return value messing up parsing of macros. We ended up having to create a {semicolon} macro that returns a semicolon.)

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 3/14/2013 7:22:50 AM
   
RE:Showing fallback web part
My suggestion would be to check out this blog post from Karol about testing macros and K#. Probably the fastest and easiest way to get the results you are looking for out of a macro.