Skip to content

Instantly share code, notes, and snippets.

@TLWebdesign
Created March 13, 2021 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TLWebdesign/1764e3b8734ddf54f7f5acc66aca40c2 to your computer and use it in GitHub Desktop.
Save TLWebdesign/1764e3b8734ddf54f7f5acc66aca40c2 to your computer and use it in GitHub Desktop.
Custom field code used in single article view override.
// loop through all the fields attached to the article.
foreach ($this->item->jcfields as $field) :
// There is the $field->params->get('your_parameter_here');
// If you have a select field and would like to retrieve the "text" values of all the options
// You can get these by using the code below. Depending on the field you replace 'options' with whatever parameter you want to fetch.
// To view all params available you can do a 'var_dump($field->fieldparams);' to display the params.
// Examples when you would want to use this: Use both text and value of a select list (by default you only have a comma seperated string of the selected texts in the $field->value, and an array of values in $field->rawvalue).
// Or if you have a repeatable field you can retrieve the field names to make the override more "dynamic".
$fieldparams = $field->fieldparams->get('options');
// There is also the $field->params->get('your_parameter_here');
// With this you can for instance retrieve render_class parameter. This i've used before to add a class in certain places.
$params = $field->params->get('render_class');
///////////////////////////////////////////
// Actual code i used
///////////////////////////////////////////
$geschiktvoor = "";
foreach ($this->item->jcfields as $field) :
if ($field->group_id == 4) :
switch ($field->name) {
case 'geschiktvoor':
$geschikt = $field->rawvalue;
$fieldoptions = $field->fieldparams->get('options');
$options = array();
foreach ($fieldoptions as $option) :
$options[$option->value] = $option->name;
endforeach;
$geschiktvoor .='<div class="col-md-6">';
foreach ($geschikt as $g) :
$geschiktvoor .='<div class="row mb-3">
<div class="col-xs-12">
<img src="/images/assortiment/horren/geschiktvoor/'.$g.'" width="80px" height="80px">
<span class="ml-5 mt-4 h5">'.$opties[$g].'</span>
</div>
</div>';
endforeach;
$geschiktvoor .='</div>';
break;
default:
$geschiktvoor .=$field->title.': '.$field->value;
}
endif; // group id 4
endforeach; // jcfields as field
// display the html just created in above script.
echo $geschiktvoor;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment