Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Conditional Wrapping Content for Editable Text WebPart View modes: 
User avatar
Member
Member
Armysniper89 - 6/11/2013 1:57:32 PM
   
Conditional Wrapping Content for Editable Text WebPart
I want to setup an EditableText web part for my content authors on a page, if they do specify text, I want to wrap the content of the web part in some HTML. Namely an H2 Tag and a span used to set a line before the text of the control. If there is NO text specified in the EditableText web part, then the wrapping text does not get displayed. I know I can do script for the Wrapper sections, but how can I check for the current control's content being empty?

User avatar
Kentico Support
Kentico Support
kentico_filipl - 6/16/2013 11:09:39 PM
   
RE:Conditional Wrapping Content for Editable Text WebPart
Hello,

You could use CMSAbstractWebPart class for setting Content Before and Content after properties for a certain Editable text web part and CMSContext.CurrentPageInfo.EditableItems["editabletext"] to get the current text content of EditableText web part.

Here is an example of using it in the code:
// Get Editable Text web part 
CMSAbstractWebPart EditableTextWebPart = this.PagePlaceholder.FindWebPart("editabletext");

// Check text content of Editable text web part
if (CMSContext.CurrentPageInfo.EditableItems["editabletext"] != "")
{
// Set Content before and Content after properties
EditableTextWebPart.ContentBefore = "<h2>Some content before</h2>";
EditableTextWebPart.ContentAfter = "<h2>Some content after</h2>";
}
else
{
// Set Content before and Content after properties to empty
EditableTextWebPart.ContentBefore = "";
EditableTextWebPart.ContentAfter = "";
}

Best regards,
Filip Ligac