Using the raw value of a field inside a template file or inside the viewing layout of another field

  • Published by
    George Papadakis
  • Last modified
    18 June 2017
  • Up to date
    Yes
  • Profile concerned
    Webdesigner, Developer
  • Concerns
    Plugins Template
  • Since Version
    3.X
  • Voting
    Average rating
    8 votes
    • 1
    • 2
    • 3
    • 4
    • 5
  • Favourites
    312 Using the raw value of a field inside a template file or inside the viewing layout of another field /documentation/tutorials-english/70-developer-api-field-plugins/312-using-the-raw-value-of-a-field-inside-a-template-file-or-inside-a-new-custom-field-type.html

To use the raw value of an item field inside a template you do not need to create the field's 'display' HTML, thus you do not need to place it in a template position.

to see the available properties of a field inside your e.g item view template file item.php (file inside FLEXIcontent template folder) use e.g. for field19 as field name:

 
$field_id = 19;

// Use in ITEM view / Category (multi-items) view
$fvals = isset($item->fieldvalues[$field_id]) ? $item->fieldvalues[$field_id] : array();


//***
//*** PRINT RAW values
//***
foreach ($fvals as $v)
{
	$is_a_serialized_value = @unserialize($v)!== false || $v=== 'b:0;';
	if ($is_a_serialized_value)
	{
		$v = unserialize($v);
	}
	echo '<pre>' . print_r($v, true) . '</pre>';
}



//***
//*** For fields select/selectmultiple/checkbox/checkboximage/radio/radioimage
//***

$field_name = 'somename';

$extra_props = array();  // For fields select/selectmultiple/checkbox/radio
$extra_props = array('image');  // For fields checkboximage/radioimage

$elements = FlexicontentFields::indexedField_getElements( $item->fields[$field_name], $item, $extra_props );
foreach ($fvals as $v)
{
	$value = @ $elements[$v]->value;
	$image = @ $elements[$v]->image;
	echo 'value: ' . $value . ' - ';
	echo 'image: ' . $value . ' <br/>';
}