How to disallow component editing in child pages? | Community
Skip to main content
LinearGradient
Level 6
October 16, 2015
Solved

How to disallow component editing in child pages?

  • October 16, 2015
  • 4 replies
  • 3768 views

Hi,

For our project we want to restrict editing of some components like Header and Footer only to the home (root) page of a Web site.

In other words, in the Touch UI, these components can be edited only if the page that is currently being edited is the home page of the current web site.

Also it should not be possible to edit and override Header and Footer in child pages.

Is there a way to create/configure suchlike components in CQ 5.6 out of the box?

Thanks in advance.

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 PaulMcMahon

What I typically in this scenario is add code in my templates that checks the current page's level and unless the page is at say level 4, or is of a particular template type I change the edit mode to disabled before including the component and switch it back to edit afterwards. 

<% boolean changed = false; if (WCMMode.fromRequest(request) == WCMMode.EDIT && page.getDepth() > 3) { WCMMode.DISABLED.toRequest(request); changed = true; } %> <cq:include path="mycom" resourceType="mysite/components/mycomp" /> <% if (changed) { WCMMode.EDIT.toRequest(request); changed = false; } %>

Now that's a lot of scriptlet so I always create a custom tag to do that for me. 

4 replies

PaulMcMahonAccepted solution
Level 8
October 16, 2015

What I typically in this scenario is add code in my templates that checks the current page's level and unless the page is at say level 4, or is of a particular template type I change the edit mode to disabled before including the component and switch it back to edit afterwards. 

<% boolean changed = false; if (WCMMode.fromRequest(request) == WCMMode.EDIT && page.getDepth() > 3) { WCMMode.DISABLED.toRequest(request); changed = true; } %> <cq:include path="mycom" resourceType="mysite/components/mycomp" /> <% if (changed) { WCMMode.EDIT.toRequest(request); changed = false; } %>

Now that's a lot of scriptlet so I always create a custom tag to do that for me. 

Scott_Brodersen
Level 8
October 16, 2015
LinearGradient
Level 6
October 16, 2015

orotas wrote...

What I typically in this scenario is add code in my templates that checks the current page's level and unless the page is at say level 4, or is of a particular template type I change the edit mode to disabled before including the component and switch it back to edit afterwards. 

  1. <%
  2. boolean changed = false;
  3.  
  4. if (WCMMode.fromRequest(request) == WCMMode.EDIT && page.getDepth() > 3) {
  5. WCMMode.DISABLED.toRequest(request);
  6. changed = true;
  7. }
  8. %>
  9. <cq:include path="mycom" resourceType="mysite/components/mycomp" />
  10. <%
  11. if (changed) {
  12. WCMMode.EDIT.toRequest(request);
  13. changed = false;
  14. }
  15. %>

Now that's a lot of scriptlet so I always create a custom tag to do that for me. 

 

Sorry, I am new to CQ. In my component's template I do not have <cq:include>, but just the component markup. Something like this:

<% boolean changed = false; if (WCMMode.fromRequest(request) == WCMMode.EDIT && page.getDepth() > 3) { WCMMode.DISABLED.toRequest(request); changed = true; } %> <% // some scriptlets %> <div class="my-component"> <!-- some markup --> </div> <% if (changed) { WCMMode.EDIT.toRequest(request); changed = false; } %>

Would this solution work if I wrap my code inside the scriptlet you've shown?

UPDATE: I tried this and it works as expected. Thanks.

Level 2
October 16, 2015

Yes, Create one admin header and footer page under tools by using a template.Add your component and give content details. After that you can easily show all those values on other pages by fetch content from nodes.