Sandeep Rawat
Sandeep Rawat

Reputation: 260

Is there any way to show all the components data from /jcr:content/par/ location

I have a query regarding the data rendering of the different page at one place. As every page is build using many components and all the components data gets stored under jcr location of page ie. /jcr:content/par/{components list}. The data is properly rendering on this page.

Now I have a situation where I need to create a component to search the page(i.e unique product), if this product page is available in the repository, I need to render its data just under the search box. For this I am creating json which I will use to render the content after search found.

But if there is any other way i can include this component from the /par location of the page to just display the data as it is, rather than building json(of all the components data) and then reading it at the time of display.

I am wondering if we have any method to display all the components data by just including the /par/{components} on a page. This way I can speed up the development, and it looks faster way to display the content as well.

thanks in advance....

Upvotes: 0

Views: 468

Answers (1)

Oleksandr Tarasenko
Oleksandr Tarasenko

Reputation: 1454

If you have static page, then you can go through list of search results (product resources) and include component, which renders product, for each of them. Like:

<c:forEach items="${productsList}" var="productPath">
    <cq:include path="${productPath}" resourceType="/apps/you-project/components/product-component-name"/>
</c:forEach>

If you show results dynamically - then you can do ajax requests for product resources. Something like this:

var productHtml = CQ.shared.HTTP.get(productPath + ".html");

Or the same using JQuery. Then you can add html to your page. However, with second approach you should add clientlibs from component /apps/you-project/components/product-component-name to search results page yourself, because they will not be loaded with ajax request.

Upvotes: 0

Related Questions