Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Empty "Editable Text" Web Part View modes: 
User avatar
Member
Member
adi-wellness-layers - 4/6/2011 7:49:02 AM
   
Empty "Editable Text" Web Part
Hi,

When i'm using Editable Text, iits content can stay empty.
My problem is that the Content Before and the Content After stay there.
I would like to get rid of them when my content is empty.
Can I do that somehow?

Thanks,
Adi.

User avatar
Kentico Developer
Kentico Developer
kentico_ondrejv - 4/19/2011 10:37:28 AM
   
RE:Empty "Editable Text" Web Part
Hello,

I would suggest you to take advantage of the Visible property of the Editable text webpart. You can see a basic example here: http://devnet.kentico.com/FAQs/Web-parts---Controls/How-to-show-hide-webpart-on-specific-document-with.aspx. Using this approach, the content before/after is shown just if the webpart has set visibility to the true value.

In your case, you can develop a custom macro which will check, whether the editable region has some content or not. It can look similar to the following code:


case "iseditableregionpopulated":
match = true;

result = "true";

if (CMS.CMSHelper.CMSContext.CurrentDocument.DocumentContent.EditableWebParts["maincontenttext"] != null) // if the editable region exists
{
string contentText = CMS.CMSHelper.CMSContext.CurrentDocument.DocumentContent.EditableWebParts["maincontenttext"].ToString(); // get its content
if (((contentText.Trim() == "") || (contentText.Trim() == "<br />")) && (CMS.CMSHelper.CMSContext.ViewMode == CMS.PortalEngine.ViewModeEnum.LiveSite)) //check whether it is empty and do that only on the live site
{
result = "false";
}
}
else if (CMS.CMSHelper.CMSContext.ViewMode == CMS.PortalEngine.ViewModeEnum.LiveSite) // if editable region doesn't exist and you are on the live site - hide it
{
return "false";
}
break;


You can call this macro like this: {% ProcessCustomMacro("iseditableregionpopulated", "") %}

Best regards
Ondrej Vasil