Версия 24.1 от HRlink на 22.08.2025

Скрыть последних авторов
HRlink 16.1 1 {{velocity}}
HRlink 21.1 2 #set($PERPAGE = 10)
3
HRlink 24.1 4 ## 1) Родитель как DocumentReference (надежно даже при "\." в именах)
5 #set($parentRef = $doc.documentReference)
HRlink 21.1 6
HRlink 24.1 7 ## Для фоллбека возьмём локальную строку и уберём .WebHome => получим префикс ветки
8 #set($local = $services.model.serialize($parentRef, 'local')) ## напр.: Blog.HRlink.-Novosti-ob-obnovleniiakh-.WebHome
9 #set($prefix = $local)
10 #if($local.endsWith('.WebHome'))
11 #set($prefix = $local.substring(0, $local.length() - 8))
HRlink 23.1 12 #end
HRlink 24.1 13 #set($prefix = $prefix + '.')
HRlink 22.1 14
HRlink 24.1 15 ## 2) Пагинация
16 #set($p = $request.get('p')) #if(!$p) #set($p = 1) #end
17 #set($p = $numbertool.toInteger($p)) #if($p < 1) #set($p = 1) #end
HRlink 21.1 18 #set($offset = ($p - 1) * $PERPAGE)
19
HRlink 24.1 20 ## 3) A) дети по parent = текущая страница (DocumentReference)
HRlink 21.1 21 #set($total = $services.query.xwql(
HRlink 24.1 22 "select count(doc.fullName) from Document doc where doc.parent = :p"
23 ).bindValue('p', $parentRef).execute().get(0))
HRlink 21.1 24
25 #set($rows = [])
26 #if($total > 0)
27 #set($rows = $services.query.xwql(
28 "select doc.fullName from Document doc " +
HRlink 24.1 29 "where doc.parent = :p order by doc.date desc"
30 ).bindValue('p', $parentRef).setLimit($PERPAGE).setOffset($offset).execute())
HRlink 21.1 31 #end
32
HRlink 24.1 33 ## 3) B) если вдруг пусто — фоллбек по префиксу полного имени (включая подкатегории)
HRlink 21.1 34 #if($total == 0)
35 #set($total = $services.query.xwql(
36 "select count(doc.fullName) from Document doc where doc.fullName like :prefix"
HRlink 24.1 37 ).bindValue('prefix', $prefix + '%').execute().get(0))
HRlink 22.1 38 #set($rows = $services.query.xwql(
39 "select doc.fullName from Document doc where doc.fullName like :prefix order by doc.date desc"
HRlink 24.1 40 ).bindValue('prefix', $prefix + '%').setLimit($PERPAGE).setOffset($offset).execute())
HRlink 21.1 41 #end
42
HRlink 24.1 43 ## 4) Рендер
HRlink 21.1 44 #if($total == 0)
45 <p>Пока нет публикаций в этой ветке.</p>
46 #else
47 #foreach($fn in $rows)
48 #set($d = $xwiki.getDocument($fn))
49 <article style="margin:14px 0; padding-bottom:10px; border-bottom:1px solid #e5e7eb">
50 <div style="color:#6b7280; font-size:.9em">$datetool.format('dd MMM yyyy', $d.date)</div>
51 <h3 style="margin:.2rem 0"><a href="$d.getURL('view')">$escapetool.html($d.displayTitle)</a></h3>
52 <div>$!d.getPlainContent().substring(0,300)…</div>
53 </article>
54 #end
55
56 #if($total > $PERPAGE)
57 #set($pages = ($total + $PERPAGE - 1) / $PERPAGE)
HRlink 24.1 58 #set($base = $doc.getURL('view'))
HRlink 21.1 59 #set($prev = $math.sub($p, 1))
60 #set($next = $math.add($p, 1))
61 <nav style="margin-top:1em; display:flex; gap:1em; align-items:center">
62 #if($p > 1)<a href="$base?p=$prev">← Назад</a>#else<span style="opacity:.5">← Назад</span>#end
63 <span>Стр. $p / $pages</span>
64 #if($p < $pages)<a href="$base?p=$next">Далее →</a>#else<span style="opacity:.5">Далее →</span>#end
65 </nav>
66 #end
67 #end
HRlink 16.1 68 {{/velocity}}