Generating dynamic resource URL

I using using Hippo v11.2.7. I currently have a component that retrieves some data, processes it, and then displays it as part of an HTML page.

I would like to make the processed data available in an alternate form (JSON) so that I can call it from another page via AJAX.

I found the “Serve a Dynamic Resource” section[1] in the Hippo documentation, which is pretty much exactly what I want. My only problem is that in the example code, the “hst.resourceURL” tag is used to generate the download link. The link the “hst.resourceURL” generates looks like:

http://localhost:8080/site/services/foo?_hn:type=resource&_hn:ref=r107&_hn:rid=json

The “hst:resourceURL” tag only appears to generate links for the current page.

What I’m trying to do is make an AJAX call to the JSON representation from a completely different page. I can get the URL for the HTML page using the “hst.link” tag, but I don’t see a way to create a URL that will access the JSON version.

In terms of the example presented in the documentation, what I’m trying to do is generate the correct URL for the “Download ICS” somewhere other than the event detail page itself.

[1] https://www.onehippo.org/11/library/concepts/component-development/serve-a-dynamic-resource.html

Thanks,

David

Why not just use the same component on that page?

I’m not sure what you’re suggesting, but I don’t believe that simply reusing the component on a different page will work in my current situation. The component used to generate the HTML representation is using hst:parametername/hst:parametervalues from the sitemap configuration to determine what is shown on the page.

So right now, if I go to http://localhost:8080/site/services/foo, the “doBeforeRender” method in the component is called, and generates an HTML representation, using the hst:parametername/hst:parametervalues in the sitemap configuration to determine what is displayed.

If I call http://localhost:8080/site/services/foo?_hn:type=resource&_hn:ref=r107&_hn:rid=json, the “doBeforeServeResource” method in the component is called, and generates a JSON representation, using the same hst:parametername/hst:parametervalues as the HTML representation.

I can get the JSON representation by calling http://localhost:8080/site/services/foo?_hn:type=resource&_hn:ref=r107&_hn:rid=json, but as far as I know I don’t have a way to generate the “?_hn:type=resource&_hn:ref=r107&_hn:rid=json” portion without using the “hst.resourceURL” tag, which only works within the template used by the component.

Basically what I’m looking for is some way to generate the URL for retrieving the JSON representation, knowing only the URL of the component, and the resourceId used for generating the JSON representation.

Thanks,

David

Hi David,

I like your elaborated question.
Unfortunately, HST Resource URL and Resource Serving phase is designed and supported only in single page level, not across multiple pages. See more comments below.

HST Action URL, Render URL and Resource URL are all designed/supported in single page level only, unlike HST Link which is mainly for generating other page links.
We don’t support any way to guarantee a consistent HST Resource URL in other page context, unlike HST Link, as a result, even if the component reference ID is being generated consistently in implementation level. The consistency was implemented for other purposes (e.g, caching), not to guarantee a consistent HST Resource URL, IIUC.

Anyway, I guess you want to reuse some code and some parameter settings at sitemap item level, whether it renders HTML or JSON.
In that case, I can think of the following alternative solution:

  1. Add one more sitemap item under /services/foo. e.g, /services/foo/json. So, the /json sitemap item will be able to inherit the sitemap item parameters from its parent (or any ancestor).
  2. Implement a custom sitemap item handler [2] and configure it at /services/foo/json. So, for example, the custom sitemap item handler may produce JSON output and return null, by which the HST Container knows the custom sitemap item handler processes the response by itself and it doesn’t have to do anything more from there.
  3. Use HST Link tag to the /services/foo/json sitemap item in other page.

You can choose to configure a single page with another JSON generating component in the second step, but I think a sitemap item handler makes it simpler and cleaner as you don’t need to deal with layout template, etc.

Regards,

Woonsan

[2] Post-Processing a Matched Sitemap Item with SiteMapItemHandlers - Bloomreach Experience Manager (PaaS/Self-Hosted) - The Fast and Flexible Headless CMS

1 Like

Woosan,

Using the sitemapitemhandler as you outlined meets our requirements.

Thanks,

David