Documentation > Services API > ServicesOutput > RenderConditionalField(PanelEntry,String,String,String,String,String)


A flexible convenience method to help in common output scenarios where rendering a tag or code fragment is dependent on the value of a PanelEntry field.

public System.String RenderConditionalField(PanelEntry,String,String,String,String,String)


panel Panel that contains the field CrownPeak.CMSAPI.PanelEntry
fieldName Name of field that will be conditional System.String
tagWrapper HTML tags that will wrap the output tagWrapper overrides codeFormat System.String
tagID ID attribute for HTML tag System.String
tagClass Class attribute for HTML tag System.String
codeFormat Custom format for outputing the field content in a formatted string System.String

Code Example



            List<PanelEntry>> panels = asset.GetPanels("List_Panel"); 
            foreach (PanelEntry entry in panels)
              Out.WriteLine( ServicesOutput.RenderConditionalField(entry, "conditionalField", "div", "first", "divClass" );
              //returns and outputs: <div id="first" class="divClass">Content of conditionalField<div>\n
              Out.WriteLine( ServicesOutput.RenderConditionalField(entry, "conditionalField_2", codeFormat: "<p><h3>Content of my conditional field:</h3> {0} </p>" );
              //returns and outputs: <p><h3>Content of my conditional field:</h3> Content of conditionalField_2 </p>

Connect with Crownpeak