Skip to main content
Level 2
Oct 16, 2015 2:27 AM UTC
Solved

Cant able to get the Template Name in Publish Instance

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.
Runal_Trivedi
Runal_TrivediAccepted solution
Level 6
Oct 16, 2015 2:27 AM UTC

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
Level 2
Aug 29, 2019 2:55 PM UTC

Instead of providing read access,

We can use ${pageProperties.cq:template}

Translate
sateeshk9319722
Level 2
Aug 20, 2019 5:50 PM UTC

please elabarate as how an we get the template name

Translate
sateeshk9319722
Level 2
Aug 20, 2019 5:36 PM UTC

please elaborate the usage

Translate
Runal_Trivedi
Runal_TrivediAccepted solution
Level 6
Oct 16, 2015 2:27 AM UTC

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

Translate
Saran_KAuthor
Level 2
Oct 16, 2015 2:27 AM UTC

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

Translate
Feike_Visser1
Employee
Oct 16, 2015 2:27 AM UTC

This is a much easier way, without changing permissions:

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

best,
Feike

Translate
Saran_KAuthor
Level 2
Oct 16, 2015 2:27 AM UTC

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

Thanks a lot for your help...

Regards,

Saran

Translate