ACF\Pro\Fields\FlexibleContent

Layout::render_as_table │ private │ ACF 6.5

Renders a layout as a table.

Method of the class: Layout{}

No Hooks.

Returns

void. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->render_as_table();

Changelog

Since 6.5 Introduced.

Layout::render_as_table() code ACF 6.8.8

<?php
private function render_as_table() {
	$sub_fields = $this->layout['sub_fields'];
	?>
	<table class="acf-table">
		<thead>
			<tr>
				<?php
				foreach ( $sub_fields as $sub_field ) {
					// Set prefix to generate correct "for" attribute on <label>.
					$sub_field['prefix'] = $this->prefix;

					// Prepare field (allow sub fields to be removed).
					$sub_field = acf_prepare_field( $sub_field );
					if ( ! $sub_field ) {
						continue;
					}

					$th_attrs = array(
						'class'     => 'acf-th',
						'data-name' => $sub_field['_name'],
						'data-type' => $sub_field['type'],
						'data-key'  => $sub_field['key'],
					);

					if ( $sub_field['wrapper']['width'] ) {
						$th_attrs['data-width'] = $sub_field['wrapper']['width'];
						$th_attrs['style']      = 'width: ' . $sub_field['wrapper']['width'] . '%;';
					}

					echo '<th ' . acf_esc_attrs( $th_attrs ) . '>';
					acf_render_field_label( $sub_field );
					acf_render_field_instructions( $sub_field );
					echo '</th>';
				}
				?>
			</tr>
		</thead>
		<tbody>
			<tr><?php $this->sub_fields(); ?></tr>
		</tbody>
	</table>
	<?php
}