Sling CMS 学习:Sling Content 组件及模板(三)

一,模板

模板定义:

<?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="&lt;!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="\{&#xd;&#xa;  &quot;jcr:primaryType&quot;: &quot;sling:Page&quot;,&#xd;&#xa;  &quot;jcr:content&quot;: {&#xd;&#xa;    &quot;jcr:primaryType&quot;: &quot;nt:unstructured&quot;,&#xd;&#xa;    &quot;jcr:title&quot;: &quot;{{title}}&quot;,&#xd;&#xa;    &quot;sling:template&quot;: &quot;/conf/quincy/site/templates/base-page&quot;,&#xd;&#xa;    &quot;sling:resourceType&quot;: &quot;quincy/components/pages/base-page&quot;,&#xd;&#xa;    &quot;published&quot;: false&#xd;&#xa;  }&#xd;&#xa;}">
            <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" />

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值