문제

I used this for specific pages that had URLs' e.g. /register, /create and etc... The code is:

function mytheme_preprocess_page(&$variables) {
     // page path
      if (arg(0) == 'fbconnect' && arg(1) == 'register' && arg(2) == 'create') {
        drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/scrollTo.js', 'file');
      }
    }

So now I was thinking how do I make load a JS reading for the CSS class, not page URL and realized that adding class for arg don't work, so this below doesn't work:

  if (arg() == 'form-item-search-block-form') {
    drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/jquery.placeholder.js', 'file');
  }

Any ideas? Newbie here.

도움이 되었습니까?

해결책

Your first example, only matches a url that is 'fbconnect/register/create'. You could do this much more easily via:

if ('fbconnect/register/create' == current_path()) {

For the second, you'll want to do that via a form alter hook specific to the search block form in a custom module. Assuming the form id is search_block it'd be:

function mymodule_form_search_block_alter(&$form, &$form_state, $form_id) {
    drupal_add_js(drupal_get_path('theme', 'mytheme') . '/js/jquery.placeholder.js', 'file');
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top