2013-05-17 22 views
1

我試圖弄清楚我怎樣才能和Anthony Male的資產庫一起使用,它也被用於PyroCMS通過控制器加載某些資產到我的模板。從控制器向模板注入文件

我有一個模板,加載特定的文件,並根據控制器,如登錄控制器我需要它注入login.js文件在腳註的底部,它會加載在模板。

任何想法?

+1

您是否閱讀過文檔? http://docs.pyrocms.com/2.1/manual/developers/tools/assets – Jeemusu

+0

是的,我有我錯過了什麼? –

+0

在上述鏈接的頂部,在基本用法下:使用Asset :: js('myfile.js');'在控制器中設置文件。然後使用'echo Asset :: render_js();' – Jeemusu

回答

1

報價安東尼男資產庫的官方文檔,可以在這裏找到:http://docs.pyrocms.com/2.1/manual/developers/tools/assets

Javascript文件可以在你的控制器使用以下,其中myfile.js是你想要的JavaScript文件被添加包含,位於assets/js/myfile.js。

// Will add assets/js/myfile 
Asset::js('myfile.js'); 

// Will add assets/admin/js/myfile.js 
Asset::js('admin::myfile.js'); 


默認情況下,資產會再壓縮這兩個文件,並將它們合併成一個單一的文件(被寫入到資產/緩存/ .js文件)。要將此文件包含在您的頁面中,請在您的視圖中使用以下內容:

echo Asset::render_js(); 
+0

謝謝。同一主題不同的問題。 http://stackoverflow.com/questions/16638002/correctly-locating-asset-file-with-asset-library –

1

你問底部底部,但我的答案會對你有用。

我使用資產庫,但不是你的只是與類似的,這是我如何處理它;

在我的控制器;

/** 
* Global header variable for header view 
* 
* @var array 
* @access protected 
*/ 
protected $header = array(); 

public function __construct() { 
    // it returns like : <script type="text/javascript" src="http://domain.com/assets/js/jquery-min.js"></script> 
    $this->header["jses"][] = js("jquery-min.js"); 
    $this->header["jses"][] = js("jquery.autogrow-textarea.js"); 
} 

public function index() { 
    // some code here 
    $this->load->view("header",$this->header); 
    // other views 
} 

在我的標題視圖;

<?php foreach ($jses as $js) echo $js; ?>