Trying to get URL document into the template document via custom HstComponent

29 views
Skip to first unread message

Johnny Hujol

unread,
Jun 19, 2017, 6:40:36 PM6/19/17
to Hippo Community
Hi,
I've been spinning around trying things and nothing gets me what I want.

should get the document 'premiumdoc' into the 'document' variable defined in the template below.

I have a freemarker template

<#include "../include/imports.ftl">
Hello Simple Content page!!

<#if document??>
<h1>${document.title?html}</h1>
<div>
<@hst.html hippohtml=document.content />
</div>
<#else>
<h1>No document found</h1>
</#if>

I have a component defined with this method

@Override
public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
super.doBeforeRender(request, response);
final HstRequestContext ctx = request.getRequestContext();

// Retrieve the document based on the URL
HippoBean document = ctx.getContentBean();

if(document == null) {
try {
log.warn("Cannot find ***** : " + request.toString());
} catch(Exception e) {
log.error("", e);
}
} else {
// Put the document on the request
request.setAttribute("document", document);
}
}

I don't understand how to configure the sitemap.
The documentation talks about the ${1}, etc I have no clue to what in the URL it refers to.
Also there a mention to para names and values for the hst:component again I feel like there is a link between the two that would make my HippoDocument form the HstComponent go magically into the template document variable so at the end I display the content of the document passed 'premiumdoc'.

What am I missing? I seem to be so close and yet I've been stuck the entire day on it.

Any help would be appreciated.
Thx
Johnny



William Borg Barthet

unread,
Jun 20, 2017, 1:56:06 AM6/20/17
to hippo-c...@googlegroups.com
Hi there,

your sitemap item is the missing link here.

A sitemap item has two main configuration elements:

componentconfigurationid - this points to the page configuration
relativecontentpath - this points to some content

The relative content path is relative to the site content root. This is something like /content/documents/myhippoproject. Here is an example if you want your sitemapitem to hit a particular document:

- hst:sitemap
 - foo (relativecontentpath = premiumdoc)

going to http://localhost:8080/site/foo will load the component hierarchy pointed to by the componentconfigurationid and the call to getContentBean() will load the content at /content/documents/myhippoproject/premiumdoc, assuming that the site content root is /content/documents/myhippoproject

With wildcard sitemap items, you can insert the dynamic part of the url into the relative content path:

- hst:sitemap
 - _any_ (relativecontentpath = ${1})

in this example, http://localhost:8080/site/abc will load  /content/documents/myhippoproject/abc and http://localhost:8080/site/abc/xyz will load  /content/documents/myhippoproject/abc/xyz. The part matched by the _any_ is what is replaces the ${1}.

Hope that helps!

William


--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-community@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-community+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--

William Borg Barthet
SOLUTION ARCHITECT / TRAINER
 william.borgbarthet@bloomreach.com
+44 739 396 4977

Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 71 Summer Street, Boston, MA 02110

DE +49 170 4074731
NL +31 20 522 44 66
US +1 877 414 47 76 (toll free)
www.onehippo.com
www.onehippo.org

Johnny Hujol

unread,
Jun 21, 2017, 4:57:58 AM6/21/17
to Hippo Community
William,
thx for the info.
I will check it out and get back as I have another issue which is deploying site and cms on a normal tomcat, but that's gonna be for another post :)

Keep u posted.
Johnny
To post to this group, send email to hippo-c...@googlegroups.com

RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.



--

William Borg Barthet
SOLUTION ARCHITECT / TRAINER
 william.borgbarthet...@bloomreach.com

Johnny Hujol

unread,
Jun 29, 2017, 3:35:47 PM6/29/17
to Hippo Community
Hi,
I tried the suggestion solution and I still have no luck with this.

Here is the output of the request:

Here is my sitemap as suggested:

Here is the content directory:


So what else am I missing?
This should work, shouldn't it?

Any help is appreciated as this is frustrating.
thx
Johnny

Johnny Hujol

unread,
Jun 29, 2017, 3:40:48 PM6/29/17
to Hippo Community
I can see the document in the cms also Content section:


So the document exists and the path is correct.

I'm doing this in a custom component:

With the simplest freemarker template


To complete the information.

Johnny Hujol

unread,
Jun 29, 2017, 3:49:17 PM6/29/17
to Hippo Community
Ok I found out what the issue was.

It is the type of the Component I extend from, instead of extending class EssentialsDocumentComponent, my custom component should extend EssentialsContentComponent and now it works :)
Reply all
Reply to author
Forward
0 new messages