So I created a custom display style following a tutorial and enabled fields to be used. I can't, however, figure out what the variables on the twig file should be to display the fields I want.

MY PHP looks like this

class Slider extends StylePluginBase {

     * {@inheritdoc}
    protected function defineOptions() {
      $options = parent::defineOptions();
      $options['path'] = array('default' => 'slider');
      return $options;


  * Does the style plugin for itself support to add fields to its output.
   * @var bool
  protected $usesFields = TRUE;

   * {@inheritdoc}
  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
    parent::buildOptionsForm($form, $form_state);

    // Path prefix for SLIDER links.

    $form['chooseImage'] = [
      '#title' => $this->t('Choose Image'),
      '#type' => 'select',
      '#description' => t('Choose where to position the title and text in the slider'),
      '#options' => ['cc' => $this->t('Center'), 'tl' => $this->t('Top Left')],


I create a theme function for the view.

function slider_theme($existing, $type, $theme, $path) {
  return array( 
    'slider' => array(
      'file' => 'extended_display_styles.theme.inc',


The extended display styles theme.inc file allows me to add options but I don't know how to add the view variables.

 function template_preprocess_views_view_slider(&$variables) {
  // View options set by user.

  $options = $variables['view']->style_plugin->options;

  // Build a two-dimension array with years and months.
  $time_pool = array();
  $frameArrayManual = array('a','b','c');
  //$options['manual'] = $variables['view']->style_plugin->manual;

  foreach ($variables['view']->result as $id => $result) {
    $created = $result->node_field_data_created;
    $created_year = date('Y', $created);
    // Month date format.
    $month_date_format = (isset($options['month_date_format'])) ? $options['month_date_format'] : 'm';
    $created_month_digits = date('m', $created);
    $created_month = date($month_date_format, $created);
    $time_pool[$created_year][$created_month_digits] = "$created_month";

  $options['time_pool'] = $time_pool;
  $options['frameArrayManual'] = array('a','b','c');

  // Update options for twig.
  $variables['options'] = $options;

I can't find any resources to figure this out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.