2011-08-24 28 views
2

的谷歌Plusone精選代碼如下所示:<g:plusone size="medium"></g:plusone>Grails和谷歌Plusone精選

不幸的是,在Grails的世界, 「G:」 被保留。

我相信你可以修改Grails庫,但我正在尋找一個更簡單的方法。 我該如何簡單地讓Grails不要把這個字符串分開?

+2

爲什麼不使用[HTML代碼+1(http://code.google.com/apis/+1button/),而不是無效的,僞命名空間, XMLish版本? – Quentin

+0

我不知道HTML版本,現在測試它,你應該回答 –

+0

你是什麼意思'g:'是保留的?對於taglib命名空間? –

回答

3

我會回答我的問題,並給向Quentin發表了評論,但沒有寫出答案(如果您發佈答案,我會選擇您作爲正確答案)。

有一個HTML版本:

<div class="g-plusone" data-size="medium"></div> 
0

那麼,唯一的解決方案是更改您正在使用的taglib。

如果您使用的標籤庫,你必須做的唯一的事情是添加靜態屬性命名命名空間你想要的名稱,如下面的例子:

static namespace = google1 
1

或者你可以在你的GSP文件輸出這樣的:

${'<g:plusone annotation="inline" href="http://www.anythinggoeshere_xyz.com"></g:plusone>'} 
0

taglib solution by James Williams大樓,我才得以呈現+1按鈕這個標籤庫,這是我在我的標籤庫文件夾命名GooglePlusOneTagLib.grooovy:

class GooglePlusOneTagLib { 

    def plusone = { attrs, body -> 
     out << "<g:plusone "+(attrs.size ? "size=${attrs.size}" : "") +"></g:plusone>" 
    } 

    def plusoneScript = { attrs, body -> 
     out << '''<script type="text/javascript"> 
        (function() { 
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; 
        po.src = 'https://apis.google.com/js/plusone.js'; 
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); 
        })(); 
        </script>''' 
    } 

} 

和則y OU只使用這些標籤在你的GSP

<g:plusone size="medium"></g:plusone> 
<g:plusoneScript /> 
+0

看完之後,我更喜歡純粹的HTML解決方案(http://stackoverflow.com/a/7219746/421356),但我會離開我的,因爲它仍然有效。 –