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

时间:2015-08-30 18:27:48

标签: list sitemap hippocms

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

最后,我想出了如何以编程方式检索站点地图项(网址)(相关页面标题) 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