Numerous problems with pagetype default content

Permalink
I am trying and failing to use the pagetype Defaults feature effectively. When I add, "Design", edit, reorder, or "precipitate" (i.e. "Setup on child pages") blocks on a pagetype defaults page (the one reached by Pages and Themes -> Page types -> [Defaults]), more often than not I get the following kinds of problems:

- duplicate blocks on child pages
- missing blocks on child pages
- wrong order of blocks on child pages
- "Design" not applied to blocks on child pages
- duplicate primary key SQL errors when re-precipitating a modified block (will paste the error message next time I run into one).

It seems that whenever a block is actually precipitated onto a child page, it is _appended_ to the area instead of being _inserted_ at the correct position. (OK, I _know_ that "correct position" can be ambiguous but please read on). Thus enforcing the right order on child pages requires un-precipitating and re-precipitating all blocks in the affected range (which could even be the whole area if the reordering involves index 0). While doing this, I often run into the other problems - missing blocks, duplicates, SQL errors.

More on reordering: whenever blocks are reordered in pagetype defaults, we should reorder the corresponding subsequences of blocks on child pages accordingly, without touching positions of other blocks. Here's some pseudocode for starters:

foreach childPage in pageType->childPages
   foreach area in pageType->areas
      //extract the subsequence of default blocks
      defaultBlocks = array()
      foreach block in area->blocksOnPage(childPage)
         if (block->isDefaultBlock)
            defaultBlocks[area->indexOfBlock(pageType.defaultsPage,block)] = block
      //sort by index in "master" area
      ksort(defaultBlocks)
      //reassemble the sequence
      result = array()
      foreach block in area->blocksOnPage(childPage)
         result[] = block->isDefaultBlock ? array_shift(defaultBlocks) : block
      //put the result back
      area->assignBlockSequence(childPage,result);


This still doesn't solve all problems nor does it always do the Right Thing, but I believe it is much better than completely ignoring the reordering of blocks in pagetype defaults.

 
jordanlev replied on at Permalink Reply
jordanlev
Page Defaults are sadly not as useful as they should be. I've given up using them as a way to edit multiple pages at once and instead only rely on it when I'm first building a site to set default content for new pages that are added afterwards.

A few things I've learned:
* Adding a block to Page Defaults doesn't add it to any other pages unless you "Setup on Child Pages".
* When you do that, the block is always added at the end of the area. Changing the order of the blocks in Page Defaults has no effect on child pages no matter what.
* If you added a block to a child page from Page Defaults, as soon as you edit the block on the child page, it becomes "disconnected" from the Page Defaults and now any changes made to Page Defaults will no longer affect that block (and if you do "Setup on Child Page" again, it will just add another copy of the block, not change the one that was already there).
* Setting the design of a block *should* work in the latest version of C5 (5.4.1.1), but maybe it's buggy or only works for newly-added pages (not existing Child Pages), or maybe it does work but you've "disconnected" a child block from the Page Defaults by editing it on its own page.
* Page Defaults have no versions. As soon as you edit a block, the changes take effect immediately (doesn't even matter if you "Exit Edit Mode" or not).

It's one thing that this functionality doesn't exist, but what makes matters even worse is that there's no indication that it actually works this way. Even a bunch of the toolbar buttons are completely useless (Versions, Properties, etc.). Why are they there? I don't know...
I have a few patches submitted to the core for the next version of C5 that will clean some of this stuff up, but it doesn't really add any functionality -- just makes it clearer what you *can't* do.

It's a major bummer, I know. I feel that the inability to edit an area on a global basis (as opposed to just one block at a time) is the one and only shortcoming of Concrete5's editing system -- everything else is possible and usually easy. But not this.

If you're feeling adventurous, there are a couple of alternate solutions out there, but none of them are perfect. You can try the free "Scrapbook Display" addon in the marketplace:
http://www.concrete5.org/marketplace/addons/scrapbook-display-basic...

Or something I whipped up a while back called "global areas":
http://www.concrete5.org/community/forums/usage/a-new-approach-to-a...

Note that there is a serious limitation to both of those approaches, though: it doesn't work for blocks that rely on the "current page" location -- most importantly if you have an autonav block that is showing "current location's siblings" or "current location's children", it will not work because it's looking to the scrapbook or template page's location, not the page that the block is being displayed on. Also, the form block doesn't work properly with those either because it will post back to the scrapbook or template page (which doesn't work, so it will fail or give errors).

But if you're only concerned with fairly straightforward blocks like "Content", "Image", etc., it might be worth it to try those out.

Best of luck.

-Jordan