Skip to content
This repository has been archived by the owner on Nov 6, 2022. It is now read-only.

4. Template Functions

Luke Carbis edited this page Jul 16, 2019 · 7 revisions

These functions are for use in your block templates.

block_field()

block_field( $name, $echo = true );

Outputs the value of a specific field.

Note: If the supplied $name doesn't exist, block_field() will return null.

Parameters

  • $name (string) (Required) The field name
  • $echo (bool) (Optional) Whether the value should be formatted and output, or returned as a variable.

Usage

Output the value of a field as text.

<p><?php block_field( 'testimonial' ); ?></p>

Return the value of a field without outputting.

$author_name = block_field( 'author', false );

Check if the value of the field is set.

$url = block_field( 'url', false );

if ( ! empty( $url ) ) {
    echo '<a href="' . $url . '">Click me!</a>';
}

block_value()

block_value( $name );

Helper function for returning the value of a field without any output. Essentially the same as block_field( $name, false );.

Parameters

  • $name (string) (Required) The field name

Usage

Return the value of a field.

$author_name = block_value( 'author' );

block_config()

block_config();

Helper function for returning the block's settings.

Usage

Outputs the block's icon.

$block = block_config();
$icon  = $block['icon'];
$icons = block_lab_get_icons();

if ( isset( $icons[ $icon ] ) ) {
	echo $icons[ $icon ];
}

block_field_config()

block_field_config( $name );

Helper function for returning the field's settings.

Note: If the supplied $name doesn't exist, block_field_config() will return null.

Parameters

  • $name (string) (Required) The field name

Usage

List all available options from a Select field.

$select = block_field_config( 'select' );
if ( isset( $select['options'] ) ) {
	foreach( $select['options'] as $option ) {
		echo '<li>' . $option['label'] . '</li>';
	}
}