Cant able to get the Template Name in Publish Instance | Community
Skip to main content
New Participant
October 16, 2015
Solved

Cant able to get the Template Name in Publish Instance

  • October 16, 2015
  • 7 replies
  • 7578 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Runal_Trivedi

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

7 replies

sateeshk9319722
New Participant
August 29, 2019

Instead of providing read access,

We can use ${pageProperties.cq:template}

sateeshk9319722
New Participant
August 20, 2019

please elabarate as how an we get the template name

sateeshk9319722
New Participant
August 20, 2019

please elaborate the usage

Runal_Trivedi
Runal_TrivediAccepted solution
New Participant
October 16, 2015

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

Saran_KAuthor
New Participant
October 16, 2015

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

Feike_Visser1
Employee
October 16, 2015

This is a much easier way, without changing permissions:

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

best,
Feike

Saran_KAuthor
New Participant
October 16, 2015

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

Thanks a lot for your help...

Regards,

Saran