如何以编程方式检索 HippoCMS 中所有页面的列表?

How to programmatically retrieve list of all pages in HippoCMS?

在 HippoCMS 中,我创建了文档类型并希望提供列出所有可用页面的动态字段,就像在 CMS 中通过频道管理器创建新页面时一样(当单击“页面”按钮时,有所有的列表页面可用)。我可以通过解析 forge-sitemap-based-on-hst-configuration-feed 提供的 sitemap.xml 来检索列表,但似乎必须有更好的方法来做到这一点。我找不到任何关于它的信息。有能力的请帮帮我

Hippo CMS 本质上是一个基于内容的 CMS。这意味着虽然您可以查看页面,但页面本身并不存在。您可以检查站点地图插件中的代码以查看它是如何完成的,但基本上您必须检查所有文档以查看它们是否已映射以及所有映射以查看是否有文档。您必须检查这两种方式,因为映射可以在模式上完成并且根本不需要引用任何文档。当然这是针对一般情况,你的情况可能更简单。

最后,我想出了如何以编程方式(具有相关页面标题)检索站点地图项目(url)。
1)添加属性hst:componentconfigurationid=hst:components/forge-sitemap-based-on-hst-configuration-feed/hst:hst/hst:configurations/hst:default/hst:sitemap/sitemap.xml
2) 创建将处理请求的组件:

public class SitemapComponent extends CommonComponent{
  @Override
  public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
    super.doBeforeRender(request, response);

    final Map<String, String> items = new HashMap<String, String>();

    List<HstSiteMapItem> siteMapItems = getHstSite(request).getSiteMap().getSiteMapItems();
    crawlSitemapItems(request, siteMapItems, items);

    request.setAttribute(REQUEST_ATTR_DOCUMENT, items);
  }

  public void crawlSitemapItems(HstRequest request, List<HstSiteMapItem> siteMapItems, Map<String, String> items) {
    HstRequestContext ctx = request.getRequestContext();

    for (HstSiteMapItem siteMapItem : siteMapItems) {
        if (siteMapItem.getPageTitle() != null) {
            HstLink link = ctx.getHstLinkCreator().create(siteMapItem, getMount(request));

            if (!link.getPath().isEmpty()) {
                int index = link.getPath().indexOf("/");
                if (index > -1) {
                    items.put(link.getPath(), siteMapItem.getPageTitle());
                }

                List<HstSiteMapItem> children = siteMapItem.getChildren();
                if (!children.isEmpty()) {
                    crawlSitemapItems(request, children, items);
                }
            }
        }
    }
  }
}

3) 将 hst:componentclassname = com.test.cms.components.SitemapComponent 设置为所需的 hst:component