I have a field collection set up for fields that make up a slider, one of these fields is for the alignment of text in the slider & is hidden on output. I'm trying to get the value of this hidden field & use it to set a CSS class in the .tpl file, I've managed to do this but only in the .tpl file itself. If I understand it correctly it's best practise to get the value of this field in a preprocess function & expose it as a variable to the .tpl file, I'm unsure how to do this.
This is what I have written in the .tpl.php file, and it works, but from what I understand it's not best practise.
$key = key($items[0]["entity"]["field_collection_item"]);
$alignment = $items[0]["entity"]["field_collection_item"][$key]["field_image"]["#object"]->field_alignment["und"][0]["value"];
I'm using the Drupal module fences to modify output so the code above is in the field--fences-xl-slider.tpl.php
file.