2012-06-27 64 views
0

我公司開發的 「汽車銷售」 的內容類型有以下字段:造型/主題化Drupal 7的內容類型記錄

  1. 廠商
  2. 型號
  3. 燃料類型
  4. 傳輸(手動/自動)
  5. 顏色
  6. 註冊? (是/否)
  7. 里程
  8. 發動機功率
  9. 狀況(全新/翻新/二手)
  10. 價格
  11. 圖片(多上傳)

我已經開發了這一內容的查看鍵入以顯示汽車列表。現在我想開發一個這樣的個人汽車銷售記錄的屏幕/視圖: enter image description here

除了安排領域,請注意,我想要在它們之間嵌入圖片庫。這可以通過Drupal 7 Admin UI實現嗎?還是需要創建自定義CSS和模板文件?如果我需要編輯某些模板文件/ css,那是什麼?我正在使用Zen Sub Theme。

回答

0

我會通過創建一個頁面,然後創建一個節點模板來完成此任務。首先創建一個新節點,然後記錄模板名稱的NID。

然後,在你的模板,創建一個新的文件,並以下列方式將其命名爲:node--[node id].tpl.php

然後,在該文件中,粘貼下面的輔助函數(或者你可以把它的template.php如果你要在你的網站上的其他地方使用它):

/** 
* Gets the resulting output of a view as an array of rows, 
* each containing the rendered fields of the view 
*/ 
function views_get_rendered_fields($name, $display_id = NULL) { 
    $args = func_get_args(); 
    array_shift($args); // remove $name 
    if (count($args)) { 
     array_shift($args); // remove $display_id 
    } 

    $view = views_get_view($name); 
    if (is_object($view)) { 
     if (is_array($args)) { 
      $view->set_arguments($args); 
     } 
     if (is_string($display_id)) { 
      $view->set_display($display_id); 
     } 
     else { 
      $view->init_display(); 
     } 
     $view->pre_execute(); 
     $view->execute(); 
     $view->render(); 
     //dd($view->style_plugin); 
     return $view->style_plugin->rendered_fields; 
    } else { 
     return array(); 
    } 
} 

然後將下面的代碼添加到您的模板:

<?php 
    $cars = views_get_rendered_fields('view name', 'default', [...any arguments to be passed to the view]); 
    foreach ($cars as $car): ?> 
    <div>Put your mockup in here. It might be helpful to run <?php die('<pre>'.print_r($car, 1).'</pre>'); ?> to see what the $car array looks like.</div> 
    <?php endforeach; 
?> 

只要改變placeh在代碼中的任何你想要標記的東西,你應該被設置!

正如我上面提到的那樣,通過<?php die('<pre>'.print_r($car,1).'</pre>'); ?>可以直觀地顯示數組看起來像打印的內容,總是有幫助的。

我在代碼中始終使用views_get_rendered_fields,因爲它允許我完全自定義視圖的輸出。

作爲提醒:每次創建新模板時都要清除緩存。

祝你好運!