Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Cant able to get the Template Name in Publish Instance

Saran_K
Level 2
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
Runal_Trivedi
Correct answer by
Community Advisor
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

0 Replies
Runal_Trivedi
Correct answer by
Community Advisor
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

Saran_K
Level 2
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

Feike_Visser1
Employee
Employee

This is a much easier way, without changing permissions:

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

best,
Feike

Saran_K
Level 2
Level 2

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

Thanks a lot for your help...

Regards,

Saran

sateeshk9319722
Level 2
Level 2

please elabarate as how an we get the template name

sateeshk9319722
Level 2
Level 2

Instead of providing read access,

We can use ${pageProperties.cq:template}