Custom field code used in single article view override.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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