Skip to main content
Category:

In this post, I'll show you how to add a class to more link of a view in Drupal 8. by implementing template_preprocess_views_view() in your theme under THEMENAME.theme file as shown below:

/**
 * Implements template_preprocess_views_view()
 * @param array $variables
 */
function THEMENAME_preprocess_views_view(&$variables)
{
    $view = $variables['view'];
    if ($view->id() == 'VIEW_ID') {
        $variables['more']['#options']['attributes']['class'][] = 'class_css';
    }
}

Example how to add a class to more link in specific page or block:

/**
 * @param $variables
 */
function THEMENAME_preprocess_views_view(&$variables)
{
    $view = $variables['view'];
    switch ($view->storage->id()) {
        case 'news':
            if ($view->current_display == 'page_1' || $view->current_display == 'block_1')  {
                $variables['more']['#options']['attributes']['class'] = 'btn btn-primary';
            }
    }
}
 

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook