An error occurred while processing the template.
The following has evaluated to null or missing:
==> entries?first.getCategories()?first  [in template "20097#20125#35643" at line 35, column 24]

----
Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
----

----
FTL stack trace ("~" means nesting-related):
	- Failed at: vocabularyId = entries?first.getCateg...  [in template "20097#20125#35643" in function "getRootCategories" at line 35, column 9]
----
1<#-- Шаблон публикатора "Библиотека документов" --> 
2 
3<#assign assetCategoryLocalService = serviceLocator.findService("com.liferay.asset.kernel.service.AssetCategoryLocalService") /> 
4<#assign assetVocabularyLocalService = serviceLocator.findService("com.liferay.asset.kernel.service.AssetVocabularyLocalService") /> 
5<#assign dLAppLocalService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLAppLocalService") /> 
6<#assign classNameService = serviceLocator.findService("com.liferay.portal.kernel.service.ClassNameLocalService") /> 
7<#assign dlUtil = staticUtil["com.liferay.document.library.kernel.util.DLUtil"]> 
8 
9<div class="knd_document_list"> 
10    <#if entries?has_content> 
11 
12        <#-- Уровень вложенности, для заголовков --> 
13        <#global level = 1 /> 
14 
15        <#if renderRequest.getParameter("categoryId")??> 
16            <#assign 
17                categoryId = renderRequest.getParameter("categoryId")?number?long 
18                categoryTree = sortEntries(categoryId, entries) 
19            /> 
20            <@parseCategoryTree categoryTree=categoryTree /> 
21        <#else> 
22            <h${level}>Все документы</h${level}> 
23            <#assign rootCategories = getRootCategories(entries) /> 
24            <#list rootCategories as rootCategory> 
25                <#global level = 2 /> 
26                <#assign rootCategoryTree = sortEntries(rootCategory.getCategoryId(), entries) /> 
27                <@parseCategoryTree categoryTree=rootCategoryTree /> 
28            </#list> 
29        </#if> 
30    </#if> 
31</div> 
32 
33<#function getRootCategories entries> 
34    <#assign 
35        vocabularyId = entries?first.getCategories()?first.getVocabularyId() 
36        rootCategories = assetVocabularyLocalService.getVocabulary(vocabularyId).getCategories() 
37            ?filter(x -> x.getParentCategoryId() == 0) 
38            ?sort_by("modifiedDate") 
39    /> 
40 
41    <#return rootCategories /> 
42</#function> 
43 
44<#function sortEntries categoryId entries> 
45    <#assign 
46        entriesProcessed = sortEntriesByCategory(entries) 
47        currentCategoryTree = buildEntriesTree(categoryId, entriesProcessed) 
48    /> 
49     
50    <#return currentCategoryTree /> 
51</#function> 
52 
53<#function sortEntriesByCategory entries> 
54    <#assign entryCategoryMap = [] /> 
55    <#assign uniqueCategories = [] /> 
56 
57    <#list entries as entry> 
58        <#if entry.getCategories()?has_content> 
59            <#assign 
60                categoryId = entry.getCategories()?first.getCategoryId() 
61                entryCategoryMap += [{ 
62                    "entry": entry, 
63                    "categoryId": categoryId 
64                }] 
65            /> 
66 
67            <#if !uniqueCategories?seq_contains(categoryId)> 
68                <#assign uniqueCategories += [categoryId] /> 
69            </#if> 
70        </#if> 
71 
72    </#list> 
73 
74    <#assign categoriesEntries = [] /> 
75 
76    <#list uniqueCategories as uniqueCategory> 
77        <#assign 
78            categoryEntries = entryCategoryMap 
79                ?filter(x -> x.categoryId == uniqueCategory) 
80                ?map(y -> y.entry) 
81                ?sort_by("modifiedDate") 
82             
83            categoriesEntries += [{ 
84                "categoryId": uniqueCategory, 
85                "entries": categoryEntries 
86            }] 
87        /> 
88    </#list> 
89 
90    <#return categoriesEntries /> 
91</#function> 
92 
93<#function buildEntriesTree categoryId entriesProcessed> 
94    <#local 
95        own = [] 
96        children = [] 
97    /> 
98 
99    <#local categoryName = assetCategoryLocalService.getCategory(categoryId).getName() /> 
100 
101    <#if entriesProcessed?filter(x -> x.categoryId == categoryId)?has_content> 
102        <#local own = entriesProcessed?filter(x -> x.categoryId == categoryId)?first.entries /> 
103    </#if> 
104 
105    <#if assetCategoryLocalService.getChildCategoriesCount(categoryId) gt 0> 
106        <#local childCategories = assetCategoryLocalService.getChildCategories(categoryId)?sort_by("modifiedDate") /> 
107        <#list childCategories as childCategory> 
108            <#local children += [buildEntriesTree(childCategory.getCategoryId(), entriesProcessed)] /> 
109        </#list> 
110    </#if> 
111 
112    <#local 
113        categoryTree = { 
114            "categoryName": categoryName, 
115            "own": own, 
116            "children": children 
117
118    /> 
119    <#return categoryTree /> 
120</#function> 
121 
122<#macro parseCategoryTree categoryTree> 
123    <#if categoryTree.own?has_content || categoryTree.children?has_content> 
124        <h${level}>${categoryTree.categoryName}</h${level}> 
125    </#if> 
126 
127    <#list categoryTree.own as curEntry> 
128        <@displayEntry entry=curEntry /> 
129    </#list> 
130 
131    <#local savedLevel = level /> 
132 
133    <#if categoryTree.children?has_content> 
134        <#-- Всего имеем шесть уровней заголовков --> 
135        <#if level < 6> 
136            <#global level++ /> 
137        </#if> 
138 
139        <#list categoryTree.children as child> 
140            <@parseCategoryTree categoryTree=child /> 
141        </#list> 
142 
143        <#--  Возвращаемся к прежнему уровню заголовков --> 
144        <#global level = savedLevel /> 
145    </#if> 
146</#macro> 
147 
148<#macro displayEntry entry> 
149    <#assign classNameId = entry.classNameId?number /> 
150    <#assign className = classNameService.fetchByClassNameId(classNameId).value /> 
151 
152    <#if className == "com.liferay.document.library.kernel.model.DLFileEntry" > 
153        <#assign assetPk = entry.classPK?number /> 
154        <#assign file = dLAppLocalService.getFileEntry(assetPk) /> 
155 
156        <#assign url = dlUtil.getDownloadURL(file, file.getFileVersion(), themeDisplay, "") /> 
157        <#assign name = entry.getTitle(locale) /> 
158        <#assign extension = file.extension /> 
159 
160        <#if file.size < 1024 * 1024 > 
161            <#assign size = file.size / 1024  /> 
162            <#assign sizeLiter = "КБ"/> 
163        <#else> 
164            <#assign size = file.size / 1024 / 1024 /> 
165            <#assign sizeLiter = "МБ"/> 
166        </#if> 
167 
168        <#if name?ends_with("." + extension) > 
169            <#assign name = name?keep_before_last(".") /> 
170        </#if> 
171 
172        <a class="knd_document_list__item" href="${url}"> 
173            <div class="knd_file_icon"></div> 
174            <div class="knd_document_list__dec"> 
175                <div class="knd_document_list__dec__name"> 
176                    ${name} 
177                </div> 
178                <div class="knd_text_additional"> 
179                    ${extension?upper_case} ${size?string["0.#"]} ${sizeLiter} 
180                </div> 
181                <div class="knd_document_list__tag_list"> 
182                    <#list entry.tagNames as tag> 
183                        <#if tag != 'документ'> 
184                            <div class="label label-dismissible label-secondary" href="?tag=${tag}"> 
185                                <span class="label-item label-item-expand"> 
186                                    ${tag} 
187                                </span> 
188                            </div> 
189                        </#if> 
190                    </#list> 
191                </div> 
192            </div> 
193        </a> 
194    </#if> 
195</#macro> 
196 
197<style> 
198    .knd_document_list h1, 
199    .knd_document_list h2, 
200    .knd_document_list h3 
201
202        margin-bottom: 1rem; 
203
204</style>