Posts

Showing posts from June, 2014

Drupal7 : How to add _blank to hyper link in views ?

如果在 Drupal7 裡面想要在系統產生出來的超連結上加入 _blank 另開視窗的標籤 該怎麼做呢? 一般都會用他內建的 rewrite 功能把 但你會發現某些東西例如檔案路徑不知道怎麼生出來 可能要裝某些 Token 才有辦法知道路徑 感覺很簡單的功能確距離好遙遠阿… 不過既然 Drupal7 是 OpenSource 就自然有熱心的朋友把這功能實做出來囉! 使用的方式也很簡單 這個 case 是當你的檔案是 pdf 或 txt 時 系統會自動在 hyper link 那加上 target="_blank" 的標籤 function THEMENAME_file_link($variables) {   $file = $variables['file'];   $icon_directory = $variables['icon_directory'];   $url = file_create_url($file->uri);   $icon = theme('file_icon', array('file' => $file, 'icon_directory' => $icon_directory));   // Set options as per anchor format described at   // http://microformats.org/wiki/file-format-examples   $options = array(     'attributes' => array(       'type' => $file->filemime . '; length=' . $file->filesize,     ),   );   // Use the description as the link text if available.   if (empty($file->description)) {     $link_text = $file->filename;

Drupal 7 : How to remove viewpoint meta data ?

這問題的需求在於客戶網站不要支援 RWD (Responsive Web Resign) 由於我用 Drupal7 + Bootstrap 3.x Bootstrap 3.x 似乎內建就把這些 RWD 給設定好了 沒辦法透過後台 admin 設定 網路上看到人家說要改掉 meta tag 最多的方式都是用 html_header_alter() 但根本沒用阿… 原因在於 viewpoint 這個 meta 不是經由 html_header_alter() 產生的 後來找到用 javascript 的方式解決了 由於我是手機才需要加入這段 js 去 override 掉原本的 meta 所以我使用 mobiledetect 這個 lib 來達到我要的效果 將 viewpoint 的 content 改成 width = 1024 (px) 至於要設定多少就看你的畫面是設計給怎樣解析度看的 code 如下: function your_module_init() {   // call Mobile_Detect lib   require_once libraries_get_path('Mobile_Detect').'/Mobile_Detect.php';   $detect = new Mobile_Detect;   if ($detect->isMobile()) {     drupal_add_js("     viewport = document.querySelector(\"meta[name=viewport]\");     viewport.setAttribute('content', 'width=1024');     ", 'inline');   } } Reference Can I change the viewport meta tag in mobile safari on the fly?