HowTo install layout/design presets ...
Permalink 2 users found helpful
... for areas and blocks within a package?
I wonder about this too. Installed content can't be "laid out"?
if you're looking to programatically add a layout to a page, try something like this:
//This is to make a new collection version. //If you do it this way, you may need to approve the changes. //Otherwise use the normal collection object $collectionVersion = $c->getVersionToModify(); //get the area you want to add it to $area = Area::get($c, 'Main'); $positionInt=1; //CREATE THE LAYOUT OBJECT //(most of these parameters are optional) $params = array('type'=>'table', 'rows'=>intval($numberOfRows), 'columns'=>intval($numberOfColumns), 'locked'=>intval($lockedBoolean), 'spacing'=>intval($columnSpacing), 'layoutID'=>$exitingLayoutID );
Viewing 15 lines of 19 lines. View entire code block.
@Tony
Very cool. This is almost what I have been looking for. My idea is to create a pagetype with an area that contains a 3 column layout.
When I add this code, a new layout is created and added to the parent area. Cool. But this happens each time I put the page in edit mode, a layout is added each time. If I want the layout to be created and added only once, how can I check that the layout has already been created and use that layout? Is there a getAreaLayoutCount() or something similar? Or a way to retrieve a named layout?
After testing, I have many unused layouts still living in the mysql Layouts table. Is there a way to clean up unused layouts? Or should I just delete them using phpmyadmin and hope I'm not deleting anything still in use?
Finally, what does the positionInt value do? What is difference between setting it to 'bottom' or 'top' versus setting $positionInt=1?
Cheers,
Bev Egan
Very cool. This is almost what I have been looking for. My idea is to create a pagetype with an area that contains a 3 column layout.
When I add this code, a new layout is created and added to the parent area. Cool. But this happens each time I put the page in edit mode, a layout is added each time. If I want the layout to be created and added only once, how can I check that the layout has already been created and use that layout? Is there a getAreaLayoutCount() or something similar? Or a way to retrieve a named layout?
After testing, I have many unused layouts still living in the mysql Layouts table. Is there a way to clean up unused layouts? Or should I just delete them using phpmyadmin and hope I'm not deleting anything still in use?
Finally, what does the positionInt value do? What is difference between setting it to 'bottom' or 'top' versus setting $positionInt=1?
Cheers,
Bev Egan
If you're getting a new layout every time you enter edit mode, you probably have the code in the wrong place. You want it in the install() function in the controller.php file at the top-level of your PACKAGE (not the block's controller.php file).
The problem with this, of course, is you don't know what pages exist when the package is installed -- but depending on what exactly you're trying to do, you could create the page in the install() function as well (see the "concrete/controllers/install.php" file for an example of how to do this).
If, on the other hand, you want this code to be run whenever a page is created, you're going to want to put it in the "on_page_add" event of the page type (seehttp://www.concrete5.org/documentation/developers/system/events... for more details about events).
The problem with this, of course, is you don't know what pages exist when the package is installed -- but depending on what exactly you're trying to do, you could create the page in the install() function as well (see the "concrete/controllers/install.php" file for an example of how to do this).
If, on the other hand, you want this code to be run whenever a page is created, you're going to want to put it in the "on_page_add" event of the page type (seehttp://www.concrete5.org/documentation/developers/system/events... for more details about events).
Installing a single_page, job and theme:
Single pages should be located in the folder "single_pages" within the package's root. Likewise, all Jobs and Themes should be in their respective folders as well ("jobs" and "themes")