How can I debug adding libraries via hooks? I am trying to attach simple css via hooks in the themes and it does not work? The code looks correct to me. It doesn't attach. What am i doing wrong?

global-styling:
  version: 8.x
  header: true
  css:
    base:
      css/main.css: 

  js:
    js/main.min.js: {}
    js/scrollreveal.js: {attributes: { defer: true} }
    src/js/vendor/picturefill/picturefill.min.js: {attributes: { defer: true} }
    js/custom.js: {attributes: { defer: true, async: true} }
    js/tp.widget.bootstrap.min.js: {attributes: { defer: true} }
    js/js.cookie.min.js: {attributes: { defer: true} }
    js/api.js: {attributes: { defer: true} }

  dependencies:
    - core/drupal
    - core/jquery

content-styling:
  css:
    base:
      css/content.css: {}

carousel-styling:
  css:
    base:
      css/carousel.css: {}


I am trying to attach css/content.css only when an entity reference to a paragraph is displayed.
I am trying to attach css/carousel.css only when an certain paragraph type (slider) is displayed

function porto_sub_preprocess_field(array &amp;$variables, $hook) {

  if(  $variables['element']['#entity_type'] == 'paragraph' ) {
     \Drupal::logger('my_module')-&gt;notice('content should be');
        // tried both these on all
        $variables['element']['#attached']['library'][] = 'porto_sub/content-styling';
        $variables['#attached']['library'][] = 'porto_sub/content-styling';
  } 
}

function porto_sub_preprocess_paragraph(&amp;$variables) {
  $paragraph = $variables['paragraph'];
  if($paragraph-&gt;getParentEntity()-&gt;bundle()=='slider') {
    \Drupal::logger('my_module')-&gt;notice('carousel should be');
    $variables['element']['#attached']['library'][] = 'porto_sub/carousel-styling';

  }
}


Then i tried....still nothing

function porto_sub_page_attachments(array &amp;$attachments) {
      $attachments['#attached']['library'][] = 'porto_sub/content-styling';
    $attachments['#attached']['library'][] = 'porto_sub/carousel-styling';


x    }

Is there some way i can debug? I get no information regarding what's wrong here.
To attach a library to a certain paragraph type you could use template_preprocess_paragraph__PARAGRAPH_TYPE() like following. Note how it's just added to the $variables array not the element.

function MYTHEME_preprocess_paragraph__slider(&amp;$variables) {
  $variables['#attached']['library'][] = 'MYTHEME/carousel-styling';
}


Same with the field. Simply use template_preprocess_field__FIELD_NAME() and attach the library directly to the $variables array.



Your content-styling and carousel-styling libraries probably should look more like following. Note how it's added as theme category, not as base. See the docs on File Structure for some info about SMACSS.

content-styling:
  css:
    theme:
      css/content.css: {}




And finally: Flush cache, flush cache and flush the cache again!!!!!!!