Theme development - version picker - how to iterate over a viewport collection, sorted by repository name

瀏覽次數:27 次
跳到第一則未讀訊息

Robert Seeger

未讀,
2023年3月17日 上午11:36:442023/3/17
收件者:Scroll Viewport Developers
I am following the recipe Switching Between Spaces Published by Scroll Versions with the Private Master approach and a viewport collection that covers all published spaces.
Since this collection is ever expanding, instead of having to modify my include/include-sidebar.vm  every time in the implementation of the version picker (rather, space picker), I am iterating over a viewport collection:

 <div class="ht-scroll-versions-select">
  <label for="ht-select-version">Version</label>
  <div data-type="master-private-space" class="ht-select-container">
    <select id="ht-select-version" class="sp-picker" name="scroll-versions:version-name" tabindex="-2">
      #foreach($version_view in $viewport.collection.members)
      <option  value = "$version_view.link" #if($repository.key.toLowerCase() == $version_view.repository.key.toLowerCase()) selected #end>
$version_view.repository.name
      </option>
      #end
    </select>
  </div>
</div>

Now the collection has grown so big that I need to iterate it in a sorted manner in order to have a defined order "by Name" in the version picker.

It seems that this is not possible using the Sort placeholder and
#foreach($version_view in $sort.asc($viewport.collection.members))
because
  • $viewport.collection.members is a list of  ViewportPlaceholder objects and those cannot be cast to java.lang.Comparable
  • I cannot tell the sort function that it should sort by property repository.name
I am relatively new to Velocity and not fluent in Java, so I have not figured out how I could
  • create a typed variable $sorted_collection for a sortable set, map or list
  • iterate over $viewport.collection.members once to populate the variable
  • sort the  $sorted_collection
  • iterate over $sorted_collection in order to create the <option> tags
Can somebody help with this simple task?

回覆所有人
回覆作者
轉寄
0 則新訊息