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