Get live variant of bean

The HippoBean class has methods to get beans by relativ path and other means. It automatically handles the hippo:handles. So you can access a bean selected in a component by something like the following code:

    public static HippoBean findHippoBean(HstRequestContext context, String path) {
        HippoBean contentBaseBean = context.getSiteContentBaseBean();
        return contentBaseBean.getBean(path);
    }

My question is: Is there an easy way to always get the live version of documents? At least in our site the provided code seems to always catch the first of the child nodes of the hippo:handle which tends to be the draft variant.

In most of my use cases I’d prefer getting the live variant or null if the document is currently not published

this is transparently handled for you and it is based on user session/jcr session…it should only get draft (preview) variant if you are using preview session (if you are logged into CMS for example and accessing document via channel manager)…otherwise, something is wrong with your setup, either on user level (security domains) or you marked your mount as a preview mount

reference:

Alright I’ll have a look at that and circle back. I was asking because we somehow managed to get an unpublished document displayed in our live site. Might have been a cache or setup issue.

Yupp, seems like we had the great idea to grant the xm.repository.admin userrole to the liveuser. After removing it things work as expected