2015-05-01 51 views
4

我是grails中的新手,我正在嘗試集成bootstrap,但是我在標籤r中有錯誤:我試圖找到一些很好的教程來將引導集成到grails中,但我可以'找到任何東西,以及任何好的解決方案。在grails中集成引導

我BuildConfig添加(我可以看到,引導安裝在我的link_to_grails_plugins)

compile ":twitter-bootstrap:3.3.4" 

我做到了,這也太:

「要包括你的引導資源以下內容添加到您的應用程序的CSS或者js文件。「

Javascript grails-app/assets/javascripts/application.js: 

//= require bootstrap 

console.log("My javascript goes here"); 
Stylesheet grails-app/assets/javascripts/application.css: 

/* 
*= require bootstrap 
*/ 

這.... 佈局

你的grails-app /視圖/佈局/ main.gsp:

<!DOCTYPE html> 
<html> 
<head> 
    <title><g:layoutTitle default="Grails"/></title> 
    <asset:stylesheet src="application.css"/> 
    <g:layoutHead/> 
</head> 
<body> 
    <g:layoutBody/> 
    <asset:javascript src="application.js"/> 
</body> 
</html> 

但是,當我把我的觀點:

<html> 
    <head> 
     <meta name="layout" content="main"/> 
     <r:require modules="bootstrap"/> 
    </head> 
<body> 
    <h1> Hello World </h1> 
</body> 
</html> 

<r:require modules="bootstrap"/>標記爲黃色,我可以閱讀未知標記(r:require)。

+1

' '來自資源插件。通過當前版本的grails,「asset-pipeline」是服務資產的默認插件。這就是爲什麼你的IDE不知道這個標籤。在使用資產管道時,可以將其刪除,因爲''已經實現了。在你自己的答案中,你宣佈bootstrap兩次 - 我不認爲這是一個好主意。您必須決定依賴範圍 - 「編譯」或「運行時」。 –

回答

3

我找到了解決方案。你必須在你的BuildConfig.groovy補充一點:

運行「:Twitter的引導:3.3.4」

我告訴所有你必須在插件代碼:

plugins { 
     // plugins for the build system only 
     build ":tomcat:7.0.55" 

     // plugins for the compile step 
     compile ":scaffolding:2.1.2" 
     compile ':cache:1.1.8' 
     compile ":asset-pipeline:1.9.9" 
     compile ":twitter-bootstrap:3.3.4" 

     // plugins needed at runtime but not for compilation 
     runtime ":hibernate4:4.3.6.1" // or ":hibernate:3.6.10.18" 
     runtime ":database-migration:1.4.0" 
     runtime ":jquery:1.11.1" 
     runtime ':twitter-bootstrap:3.3.4' 

     // Uncomment these to enable additional asset-pipeline capabilities 
     //compile ":sass-asset-pipeline:1.9.0" 
     //compile ":less-asset-pipeline:1.10.0" 
     //compile ":coffee-asset-pipeline:1.8.0" 
     //compile ":handlebars-asset-pipeline:1.3.0.3" 
    }