Expand my Community achievements bar.

SOLVED

Cant able to get the Template Name in Publish Instance

Avatar

Level 2

Hi Guys,

Needed your help. I am using currentPage.getTemplate() in one of my design_dialog components for getting the Template Name (currentPage.getTemplate().getName()) and it works fine in my Author Instance.

But in Publish Instance the same component is throwing Null pointer exception. On debugging the same, i found that the currentPage.getTemplate() is returning null .

I am bit confused on this, please explain me what exactly is happening and how to get the current Page Template name in Publish Instance. Please help on this, Thanks.

Regards,

Saran

+91 9994040417

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

I guess you are trying to read it as anonymous user. By default anonymous user doesn't have even read rights on template path.

So when you do currentPage.getTemplate().getName() it is going to return null all the time.

To fix this, you will need to provide read rights to anonymous user on your template path.

You can provide read rights from OSGI Console using config option available for Day CQ ACL Setup Service (com.day.cq.security.ACLSetup), put the entry like allow;jcr:read;anonymous;/apps/<project_identifier>/templates, I cannot recall if CQ restart is required, you can cross check from permissions console tab if it took new permissions for anonymous user.

You can also directly go and configure permissions for using the permissions tab.

As per me, configuring via OSGI Config is better approach as you can push those configure using config XML's.

Hope it helps.

- Runal

View solution in original post

7 Replies

Avatar

Correct answer by
Community Advisor

I guess you are trying to read it as anonymous user. By default anonymous user doesn't have even read rights on template path.

So when you do currentPage.getTemplate().getName() it is going to return null all the time.

To fix this, you will need to provide read rights to anonymous user on your template path.

You can provide read rights from OSGI Console using config option available for Day CQ ACL Setup Service (com.day.cq.security.ACLSetup), put the entry like allow;jcr:read;anonymous;/apps/<project_identifier>/templates, I cannot recall if CQ restart is required, you can cross check from permissions console tab if it took new permissions for anonymous user.

You can also directly go and configure permissions for using the permissions tab.

As per me, configuring via OSGI Config is better approach as you can push those configure using config XML's.

Hope it helps.

- Runal

Avatar

Level 2

Thanks Runal. As you suggested, on providing the Read access to Anonymous users i can able to get the values. 

Thanks a lot.

Regards,

Saran

Avatar

Employee

This is a much easier way, without changing permissions:

page.getProperties().get("cq:template","")

best,
Feike

Avatar

Level 2

Yes Feike. This helps. I can able to get the required output... 

Thanks a lot for your help...

Regards,

Saran

Avatar

Level 3

please elabarate as how an we get the template name

Avatar

Level 3

Instead of providing read access,

We can use ${pageProperties.cq:template}