<#macro templateList filepath=''>
    <@tools.fileList path=filepath>
        <#list list as a>
            <#if !a.directory><@t.merge 'paths' filepath?has_content?then(filepath+'/','')+a.fileName/></#if>
        </#list>
        <@sys.lock userId=admin.id itemType='template' itemIds=t.paths><#assign lockMap=map!/></@sys.lock>
        <#if lockMap?has_content>
            <#list lockMap as k,lock>
                <#if lock.userId?has_content><@t.merge 'userIds' lock.userId/></#if>
            </#list>
        </#if>
        <@sys.user ids=t.userIds><#assign userMap=map!/></@sys.user>
        <#list list as a>
            <#local currentPath=filepath?has_content?then(filepath+'/','')+a.fileName>
            <li<#if a.directory><#if (path?has_content && path?starts_with(currentPath+'/'))> class="expand"<#else> _src="cmsTemplate/list.html?parent=${currentPath?url}"</#if><#elseif path?has_content && path=currentPath> class="selected"</#if>>
                <@tools.metadata path=currentPath>
                    <a href="cmsTemplate/${a.directory?then('directory','content')}.html?path=${(currentPath?url)!}" target="ajax" rel="cmsTemplateBox">
                        <#if !a.directory && lockMap?has_content && lockMap[currentPath]?has_content>
                            <#assign lockUser=(userMap[lockMap[currentPath].userId?string].nickname)!''/>
                            <i class="icon-lock icon-large" title="<@t.page 'lock.message' lockUser/> ${lockMap[currentPath].createDate}"></i>
                        </#if>
                        ${(object.alias)?has_content?then(object.alias+' '+a.fileName,a.fileName)}
                    </a>
                </@tools.metadata>
                <#if a.directory && path?has_content && path?starts_with(currentPath+'/')>
                    <ul>
                         <@templateList currentPath/>
                    </ul> 
                </#if>
            </li>
        <#else>
            <li><a><@t.page 'empty_directory'/></a></li>
        </#list>
    </@tools.fileList>
</#macro>
<#if parent?has_content>
     <ul>
         <@templateList parent/>
     </ul>
<#else>
    <div class="pageContent">
        <div class="leftPageContent">
            <div class="card">
                <h2 class="contentTitle">
                    <a class="button" href="cmsTemplate/metadata.html" target="ajax" rel="cmsTemplateBox"><@t.page 'template.create'/></a>
                    <a class="button" href="cmsTemplate/demo.html" target="dialog" mask="true"><@t.page 'template.example'/></a></li>
                </h2>
                <ul class="tree treeFolder" layoutH>
                    <@templateList/>
                </ul>
            </div>
        </div>
        <div id="cmsTemplateBox" class="unitBox rightPageContent">
            <#if path?has_content>
                <#if editType?has_content&&'metadata'=editType>
                    <#include "metadata.html"/>
                <#else>
                    <#include "content.html"/>
                </#if>
            <#else>
                <#include "directory.html"/>
            </#if>
        </div>
    </div>
</#if>