0

the css file style.css never get loaded when using the form api #attached properties. here is my code:

mymodule_menu() {

  $items['test'] = array (
            'title' => t('test css'),
            'page callback' => 'drupal_get_form',
            'page arguements' => array('test_attach_css'),
            'access callback' => TRUE,
            );

return $items;

}

function test_attach_css($form,$form_state) {
   $markup = '<p class="test">style the font as red</p>';
   $form['content']['#markup']  = $markup;
   $form['content']['#attached']['css'][] = drupal_get_path("module",       "mymodule")."/style.css";


return $form;
  }

the content of css file:

.test {

 color:red;

}

4
  • have you tried kpr(drupal_get_path("module", "mymodule")."/style/style.css");?
    – Mołot
    May 1, 2014 at 9:38
  • Just to clear up any confusion - nothing in the code above uses the form API. Perhaps you can describe what you're trying to do, and why you think you need the FAPI?
    – Clive
    May 1, 2014 at 9:41
  • Sorry for the confusion. i've changed the question. i want to theme a radio form which needs a custom styling. but for some reason, i cannot load the css file with #attached property. it works if i added the styling codes in the theme's main style file.if i remember correctly, the attached property also works with render array api. please correct me if i'm wrong.
    – JIA
    May 1, 2014 at 13:09
  • @Mołot, the css file path is correct. i can access it via the browser
    – JIA
    May 1, 2014 at 13:11

1 Answer 1

0

after many hours of searching and debugging for an anwser, i finally realize it's a naming issue. you cannot name the css file as style.css. i changed the name to custom.css,then it works as expected!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.