Online allowing one block to fit in a single content area. i.e. Only allowing one menu in a content area.

Permalink 1 user found helpful
I've played around with Concrete 5 for a number of projects and I've also developed a number of custom themes, but there's one thing that's ALWAYS bothered me since I started.

I love being able to have multiple blocks in a content area of my page, but that's doesn't always work out. For example, I like to create fancy menus using all sorts of CSS tricks. Which works fine until I want to edit my page.

So I click on Edit and then I see a box that changes how my entire menu looks while editing. This box says, "Add To Sitewide Nav." Since the menu takes up the entire width of the DIV it's inside of, the add another block button gets positioned underneath and stretches my menu vertically. This is kind of confusing to some of my other admins who don't understand how HTML and CSS work.

Is there anyway that I can disable that from appearing once I've already added a block into that area? So once I add a menu, is there anyway that I'd only be able to edit that menu or delete it before adding another menu within that same content area?

I'm sorry if this has been answered somewhere else, I cannot seem to find it while browsing around the website.

matthewalan
 
glockops replied on at Permalink Reply
glockops
You have multiple options here:
You can call the block directly from the theme if you'd like - to prevent anyone from messing with it - this is what I do with autonav blocks.

You can use an if statement to determine if the page is in edit mode and either modify the styles of the area so it still fits with the editing border around it or hide the area from everyone except a certain user or usergroup.

To insert a block in a theme:
(Note you can find the values for a particular block by viewing it's controller and db.xml files)
<?php
$nav_side = BlockType::getByHandle('autonav'); 
$nav_side->controller->displayPages = 'custom'; 
$nav_side->controller->displayPagesCID = 1;
$nav_side->controller->orderBy = 'display_asc'; 
$nav_side->controller->displaySubPages = 'all';
$nav_side->controller->displaySubPageLevels = 'custom';  
$nav_side->controller->displaySubPageLevelsNum = 1;
$nav_side->controller->displayPagesIncludeSelf = 1; 
$nav_side->render('view');
?>


To modify styles if in edit mode:
<?php if($c->isEditMode()) {
  // Do something when page is in edit mode
  // Such as adjust the width of the element, etc
?>


To prevent the block area from showing up entirely (except for the Super Admin):
<?php 
$yourArea = new Area("Your Area");
$u = new User();
if(!($c->isEditMode()) || $u->isSuperUser()) {
  // This will only show the area if the page is not in edit mode or if the super user is logged in. Note: Prevents editing by anyone other than the super user.
  $yourArea->display($c);
} ?>
arrestingdevelopment replied on at Permalink Reply
arrestingdevelopment
Another option... especially if you're talking about an area in your site where you ONLY need to have a single block (like in a Header_Nav block), is to limit the area to only allowing a single block.

This only works if you're hard-coding the auto-nav into your theme, but it would work like this. Instead of putting this in your theme:

<?php 
   $a = new Area('Header Nav');
   $a->display($c);
?>


Add another line to tell Concrete5 to limit the number of blocks allowed in the area like this:
<?php 
   $a = new Area('Header Nav');
   $a->setBlockLimit(1);
   $a->display($c);
?>


Now, once you've put your auto-nav block into that area of your site, you've used up your limit of blocks, so there won't be the "Add to Sitewide Nav" box/link showing.

Just an option.

- John
looeee replied on at Permalink Reply
This works, but there is still a box in edit mode saying "add to Header Nav" after you have added the first block. The only difference is that when you click on it to add a second block, the only option available is "design".
snookian replied on at Permalink Reply
Did you figure this out? I have a situation where I need exactly what you are asking for.