Introduction
View classes are essential for modifying the markup within Gravity Forms. They require a specific structure to ensure proper handling of markup elements. To implement a View class, developers must extend the base Gravity_Forms\Gravity_Forms\Theme_Layers\API\View and define the get_markup() method.
Usage
The get_markup()
method needs to return a string representing the final markup to be rendered. The method can either completely replace the markup with something unique, or modify the markup with new values, depending on the developer’s needs.
// An example of a View that adds the Form ID to the end of every Text input
public function get_markup( $content, $form, $value, $lead_id, $form_id ) {
$new_content = $content . '<h3>' . $form_id . '</h3>';
return $new_content;
}
Settings Reference
get_markup()
arguments.
Argument | Description |
---|---|
$content | The current markup for the field/form |
$object | The field or form object being rendered |
$value | The value of the field, or null if dealing with a form |
$lead_id | The lead_id being dealt with, if applicable |
$form_id | The ID of the form being rendered |