Expand my Community achievements bar.

SOLVED

How to disallow component editing in child pages?

Avatar

Level 7

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.

1 Accepted Solution

Avatar

Correct answer by
Level 8

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. 

View solution in original post

4 Replies

Avatar

Correct answer by
Level 8

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. 

Avatar

Level 7

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.

Avatar

Level 2

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.