acf_field_flexible_content::render_field
Create the HTML interface for your field
Method of the class: acf_field_flexible_content{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$acf_field_flexible_content = new acf_field_flexible_content(); $acf_field_flexible_content->render_field( $field );
- $field(required)
- .
Changelog
| Since 3.6 | Introduced. |
acf_field_flexible_content::render_field() acf field flexible content::render field code ACF 6.0.4
<?php
function render_field( $field ) {
// defaults
if ( empty( $field['button_label'] ) ) {
$field['button_label'] = $this->defaults['button_label'];
}
// sort layouts into names
$layouts = array();
foreach ( $field['layouts'] as $k => $layout ) {
$layouts[ $layout['name'] ] = $layout;
}
// vars
$div = array(
'class' => 'acf-flexible-content',
'data-min' => $field['min'],
'data-max' => $field['max'],
);
// empty
if ( empty( $field['value'] ) ) {
$div['class'] .= ' -empty';
}
// no value message
$no_value_message = __( 'Click the "%s" button below to start creating your layout', 'acf' );
$no_value_message = apply_filters( 'acf/fields/flexible_content/no_value_message', $no_value_message, $field );
$no_value_message = sprintf( $no_value_message, $field['button_label'] );
?>
<div <?php echo acf_esc_attrs( $div ); ?>>
<?php acf_hidden_input( array( 'name' => $field['name'] ) ); ?>
<div class="no-value-message">
<?php echo acf_esc_html( $no_value_message ); ?>
</div>
<div class="clones">
<?php foreach ( $layouts as $layout ) : ?>
<?php $this->render_layout( $field, $layout, 'acfcloneindex', array() ); ?>
<?php endforeach; ?>
</div>
<div class="values">
<?php
if ( ! empty( $field['value'] ) ) :
foreach ( $field['value'] as $i => $value ) :
// validate
if ( empty( $layouts[ $value['acf_fc_layout'] ] ) ) {
continue;
}
// render
$this->render_layout( $field, $layouts[ $value['acf_fc_layout'] ], $i, $value );
endforeach;
endif;
?>
</div>
<div class="acf-actions">
<a class="acf-button button button-primary" href="#" data-name="add-layout"><?php echo acf_esc_html( $field['button_label'] ); ?></a>
</div>
<script type="text-html" class="tmpl-popup"><ul>
<?php
foreach ( $layouts as $layout ) :
$atts = array(
'href' => '#',
'data-layout' => $layout['name'],
'data-min' => $layout['min'],
'data-max' => $layout['max'],
);
?>
<li><a <?php echo acf_esc_attrs( $atts ); ?>><?php echo acf_esc_html( $layout['label'] ); ?></a></li>
<?php
endforeach;
?>
</ul>
</script>
</div>
<?php
}