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';
            }
    }
}
 

Comments

Add new comment

Restricted HTML

Search

Page Facebook

Become a patron

If you need some help or you search a Drupal freelancer don't hesitate to contact us.

 

Contact Us

All the content is FREE but I still need your help

 

Become a patreon