在本節中,由於範本已設定在初始應用程式區段中,而初始頁面已設定在初始內容區段中,因此可使用包括啟用使用Communities元件編寫功能的基礎指令碼來開發應用程式。 在本節結束時,網站將可正常運作。
在新增轉譯播放頁面範本的元件時建立的預設指令碼,會加以修改,以包含基礎頁面的head.jsp和本機body.jsp。
第一步是向/apps/an-scf-sandbox/components/playpage
節點添加資源super type屬性,以便它繼承超類型的指令碼和屬性。
使用CRXDE Lite:
選擇節點/apps/an-scf-sandbox/components/playpage
。
在「屬性」頁籤中,輸入具有以下值的新屬性:
名稱: sling:resourceSuperType
類型: String
值: foundation/components/page
按一下綠色+Add按鈕。
按一下保存全部。
在CRXDE Lite瀏覽器窗格中,導覽至/apps/an-scf-sandbox/components/playpage
並連按兩下檔案playpage.jsp
,以在編輯窗格中開啟它。
/apps/an-scf-sandbox/components/playpage/playpage.jsp
<%--
An SCF Sandbox Play Component component.
This is the component which renders content for An SCF Sandbox page.
--%><%
%><%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false" %><%
%><%
// TODO add your code here
%>
請注意開啟/關閉指令碼標籤,請取代" // TODO …" 包含用於 <html>.
如果超類型為foundation/components/page
,則未在此資料夾中定義的任何指令碼都將解析為/apps/foundation/components/page
資料夾中的指令碼(如果存在),否則解析為/libs/foundation/components/page
資料夾中的指令碼。
/apps/an-scf-sandbox/components/playpage/playpage.jsp
<%--
An SCF Sandbox Play Component component: playpage.jsp
This is the component which renders content for An SCF Sandbox page.
--%><%
%><%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false" %>
<html>
<cq:include script="head.jsp"/>
<cq:include script="body.jsp"/>
</html>
基礎指令碼head.jsp
不需要覆蓋,但基礎指令碼body.jsp
為空。
若要設定編寫功能,請以本機指令碼覆蓋body.jsp
,並在內文中加入段落系統(parsys):
導航到 /apps/an-scf-sandbox/components
.
選擇playpage
節點。
按一下右鍵並選擇Create > Create File...
按一下保存全部。
開啟/apps/an-scf-sandbox/components/playpage/body.jsp
並貼入下列文字:
<%--
An SCF Sandbox Play Component component: body.jsp
This is the component which renders content for An SCF Sandbox page.
--%><%
%><%@include file="/libs/foundation/global.jsp"%><%
%><%@page session="false" %>
<body>
<h2>Community Play</h2>
<cq:include path="par" resourceType="foundation/components/parsys" />
</body>
按一下保存全部。
在編輯模式下在瀏覽器中檢視頁面:
您不僅應看到標題Community Play,還應看到編輯頁面內容的UI。
當兩個側面板都開啟且視窗足夠寬,以便同時顯示側面內容和頁面內容時,就會看到「資產/元件」側面板。
以下是播放頁面在傳統UI中的顯示方式,包括內容搜尋器(cf):
要啟用Communities元件進行編寫,請從以下說明開始:
為此沙盒的目的,請從以下Communities元件開始(勾選方塊即可啟用):
此外,選擇General元件,例如
為頁面par啟用的元件作為components
屬性的值儲存在儲存庫中
/etc/designs/an-scf-sandbox/jcr:content/playpage/par
節點。
在多語言環境中,根頁面將包含一個指令碼,該指令碼將解析來自客戶端的請求以確定首選語言。
在這個簡單範例中,根頁面會靜態設定為重新導向至英文頁面,未來可能會開發成具有播放頁面連結的主著陸頁面。
將瀏覽器URL變更為根頁面:http://localhost:4502/editor.html/content/an-scf-sandbox.html
選取「頁面資訊」圖示
選擇開啟屬性
在「高級」頁籤上
按一下確定
發佈網站後,瀏覽至發佈例項的根頁面會重新導向至英文頁面。
使用社區SCF元件前的最後一個步驟是添加客戶端庫資料夾(clientlibs)。… 新增Clienlibs