n Add a class to more link of a view in Drupal 8 | CodimTh

Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
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