一,模板
模板定义:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sling="http://www.sling.apache.org/sling/1.0"
jcr:primaryType="sling:Config"
jcr:title="Quincy Site Configuration"
sling:resourceType="sling-cms/components/cms/siteconfig">
<rewrite
jcr:primaryType="nt:unstructured"
attributes="[action,href,src]"
doctype="<!DOCTYPE html>"/>
<templates jcr:primaryType="nt:unstructured">
<base-page
jcr:primaryType="nt:unstructured"
jcr:title="Quincy - Base Page"
sling:resourceType="sling-cms/components/cms/pagetemplate"
allowedPaths="[/content]"
availableComponentTypes="[General,Quincy,HUWEI How To]"
template="\{
 "jcr:primaryType": "sling:Page",
 "jcr:content": {
 "jcr:primaryType": "nt:unstructured",
 "jcr:title": "{{title}}",
 "sling:template": "/conf/quincy/site/templates/base-page",
 "sling:resourceType": "quincy/components/pages/base-page",
 "published": false
 }
}">
<fields jcr:primaryType="nt:unstructured">
<text
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/text"
label="Title"
name="title"
required="{Boolean}true"
type="text"/>
<text_1147023191
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/text"
label="Name"
name=":name"
required="{Boolean}true"
type="text"/>
</fields>
<componentConfigurations jcr:primaryType="nt:unstructured">
<componentconfig
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/cms/componentconfig"
columns="[50-50=col-md-6 col-md-6,100=col-md-12]"
containerclass="container"
type="reference/components/general/columncontrol"/>
</componentConfigurations>
</base-page>
</templates>
</jcr:root>
模板引用:
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sling="http://www.sling.apache.org/sling/1.0"
jcr:primaryType="sling:Component"
jcr:title="Quincy - Base Page"
sling:resourceSuperType="reference/components/pages/base"
componentType="Page">
<edit
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/slingform"
button="Save Page">
<fields
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/general/container">
<title
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/text"
label="Title"
name="jcr:title"
required="{Boolean}true"/>
<description
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/textarea"
label="Description"
name="jcr:description"/>
<taxonomy
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/taxonomy"
label="Keywords"
name="sling:taxonomy"/>
<taxonomyTypeHint
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/hidden"
name="jcr:content/sling:taxonomy@TypeHint"
value="String[]"/>
<canonical
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/path"
basePath="/content"
label="Canonical"
name="canonical"
titleProperty="jcr:content/jcr:title"
type="sling:Page"/>
<published
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/select"
label="Published"
name="published">
<options jcr:primaryType="nt:unstructured">
<yes
jcr:primaryType="nt:unstructured"
label="Yes"
value="true"/>
<no
jcr:primaryType="nt:unstructured"
label="No"
value="false"/>
</options>
</published>
<publishedTypeHint
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/hidden"
name="published@TypeHint"
value="Boolean"/>
<hideInSitemap
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/select"
label="Hide in Sitemap"
name="hideInSitemap">
<options jcr:primaryType="nt:unstructured">
<no
jcr:primaryType="nt:unstructured"
label="No"
value="false"/>
<yes
jcr:primaryType="nt:unstructured"
label="Yes"
value="true"/>
</options>
</hideInSitemap>
<hideInSitemapTypeHint
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/hidden"
name="hideInSitemap@TypeHint"
value="Boolean"/>
<template
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/text"
disabled="{Boolean}true"
label="Template"
name="sling:template"/>
</fields>
</edit>
</jcr:root>
CSS and JS:
路径如下:/static/clientlibs/quincy/
<link rel="stylesheet" href="/static/clientlibs/quincy/.../add.css" type="text/css">
<script type="text/javascript" src="/static/clientlibs/quincy/.../add.js"></script>
基本的base.jsp:
<%@include file="/libs/sling-cms/global.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Apache Sling :: ${resource.valueMap['jcr:title']}</title>
<link rel="icon" href="/static/clientlibs/reference/img/favicon.ico"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/>
<script src='https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js'></script>
<script>
hljs.initHighlightingOnLoad();
</script>
</head>
<body>
<sling:call script="/libs/sling-cms/components/editor/scripts/init.jsp" />
<h1>Base Page</h1>
<div>
<sling:include path="container" resourceType="sling-cms/components/general/container" />
</div>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<sling:call script="/libs/sling-cms/components/editor/scripts/finalize.jsp" />
</body>
</html>
二,组件
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:sling="http://www.sling.apache.org/sling/1.0"
jcr:primaryType="sling:Component"
jcr:title="Component for Testing"
componentType="HUWEI How To">
<edit
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/slingform"
button="Save">
<fields
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/general/container">
<text
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/text"
label="Text"
name="text"
required="{Boolean}true"/>
<textarea
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/textarea"
label="Textarea"
name="textarea"
required="{Boolean}true"/>
<path
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/path"
basePath="/content"
label="Path"
name="path"
required="{Boolean}true"
type="sling:File"/>
<number
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/text"
label="Number"
name="number"
required="{Boolean}true"
type="number"/>
<dropdown
jcr:primaryType="nt:unstructured"
sling:resourceType="sling-cms/components/editor/fields/select"
label="Dropdown"
name="dropdown">
<options jcr:primaryType="nt:unstructured">
<option1
jcr:primaryType="nt:unstructured"
label="Distance"
value="distance"/>
<option2
jcr:primaryType="nt:unstructured"
label="No distance"
value="noDistance"/>
</options>
</dropdown>
</fields>
</edit>
</jcr:root>
引用组件:
<sling:include path="container" resourceType="sling-cms/components/general/container" />