Liferay 的 web content有template這個功能可以幫助我們輕鬆得到可以自訂訊息的網頁物件,

例如跑馬燈的訊息乃至圖片輪播的圖片都可以進行自定義,在快速開發簡易功能時很好用,不需自行編寫與資料庫連結的code。

現在來製作一個可以定義多重訊息的跑馬燈,首先開啟web content的Structure

在<root>加入以下;

<dynamic-element name="marqueeText" type="selection_break" index-type="" repeatable="true">
<dynamic-element name="subText" type="text" index-type="" repeatable="false"/>
</dynamic-element>

selection_break有點類似一個個的區塊,將我們要自行輸入變數的subText包在其中,repeatable設定可增加多重訊息。

這個XML定義完之後就像這樣;

webContent結構  

 

可以自行輸入想要的訊息並儲存,下一步就是將這些變數拿來用在跑馬燈上;

點擊Templates,加入一個新的Template,並將剛才的Structure加入,接著再輸入Script;

<p style="
background-image: url('/documents/10740/38551/topAndBottom.jpg');
border-radius: 4px;
color:#EEE;
padding:5px;
font-size: 12px;
font-weight: bold;
line-height:20px;">
<marquee align="" direction="left" height="20" scrollamount="3" >
#foreach($childText in $marqueeText.getSiblings())
$childText.subText.getData()
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
#end
</marquee>
</p>

先寫了一個段落p,並且可設定它的style,重點在跑馬燈marquee之中,

#foreach($childText in $marqueeText.getSiblings())

這個foreach是template所使用的,$marqueeText.getSiblings()就是剛才定義的一個個區塊,然後設定childText去跑

$childText.subText.getData()便可以將自行輸入的訊息抓出,在這裡的迴圈是有幾組訊息區塊就跑幾次,迴圈的#end就相當於"}",

完成之後長得像這樣;

template跑馬燈  

在Liferay6.1.2 ga3中,要抓子訊息似乎只要$childText.getData()就可以,尚未確認。

 

2/26補充:

關於TQE跑馬燈設定
1. HTML都以CSS設定間距來代替輸入一堆空格,先用<span>來做訊息相關設定
    如果是多個訊息,也可以考慮由下往上捲,但速度要慢一點。
2. 背景原圖 height: 31px
    把部分的設定放到marquee
    且用div enclose
arrow
arrow
    全站熱搜

    squall75726 發表在 痞客邦 留言(0) 人氣()