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

RenderConditionalField

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

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

Parameters

NameDescriptionType
asset Asset that contains the field CrownPeak.CMSAPI.Asset
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 the HTML tag System.String
tagClass Class attribute for the HTML tag System.String
codeFormat Custom format for outputing the field content in a formatted string System.String

Code Example

C#

Sample:

            Out.WriteLine( ServicesOutput.RenderConditionalField(asset, "conditionalField", "div", "first", "divClass" );
            //returns and outputs: <div id="first" class="divClass">Content of conditionalField<div>\n
            
            Out.WriteLine( ServicesOutput.RenderConditionalField(asset, "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