<#macro templateTree field filepath=''>
    <@tools.fileList path=filepath>
        <#list list as a>
            <#local path=filepath+'/'+a.fileName/>
            <li<#if a.directory> _src="cmsTemplate/lookup.html?field=${(field?url)!'path'}&parent=${path}"</#if>>
                <#if a.directory>
                    <a href="javascript:;" onclick="return false;">${a.fileName}</a>
                <#else>
                    <@tools.metadata path=path>
                        <a href="javascript:;" onclick="$.bringBack({'${field!'path'}':'${path}'});return false;">
                            ${(object.alias)?has_content?then(object.alias+' '+a.fileName,a.fileName)}
                        </a>
                    </@tools.metadata>
                </#if>
            </li>
        <#else>
            <li><a><@t.page 'empty_directory'/></a></li>
        </#list>
    </@tools.fileList>
</#macro>
<#if parent?has_content>
     <ul>
         <@templateTree field parent/>
     </ul>
<#else>
<div class="pageFormContent" layoutH>
    <ul class="tree treeFolder">
        <@templateTree field/>
    </ul>
    <script>
        $('a[data="${(value?js_string)!}"]',$.pdialog.getCurrent()).parent().addClass('selected');
    </script>
</div>
<div class="formBar">
    <ul>
        <li><a href="javascript:;" onclick="$.bringBack({'${field!'path'}':''});return false;"><@t.page 'button.clear_select'/></a></li>
        <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
    </ul>
</div>
</#if>