Setting Default Content for a Composer Block
Permalink
I'm putting together a basic site for a plant seller that will largely consist of a page for each plant he is selling, and to save time I'm trying to set things up so each page can be completely created through composer. This means composer blocks, page title blocks, etc. all defined in a page type.
It's been decided that each page will feature a table with a list of information specific to that plant. Determinacy, days to maturity, light level, and so on; the exact list hasn't been decided yet. So I'm looking for a way for the user to be able to simply input the values into the table, without having to rebuild and format the table for every page.
I realize I can make page attributes for each table row, and then use a custom block to output this in a table. But I don't want the user to have to scroll the composer window all the way down to enter 8+ attributes. Currently my line of thought is running towards a content block with the table and row name premade. I've been looking through old videos and help files, and it seems that this was possible in an old version of C5, but I don't see any way to do this in the current version.
Is there a simple way to accomplish this? Should I try a different approach?
It's been decided that each page will feature a table with a list of information specific to that plant. Determinacy, days to maturity, light level, and so on; the exact list hasn't been decided yet. So I'm looking for a way for the user to be able to simply input the values into the table, without having to rebuild and format the table for every page.
I realize I can make page attributes for each table row, and then use a custom block to output this in a table. But I don't want the user to have to scroll the composer window all the way down to enter 8+ attributes. Currently my line of thought is running towards a content block with the table and row name premade. I've been looking through old videos and help files, and it seems that this was possible in an old version of C5, but I don't see any way to do this in the current version.
Is there a simple way to accomplish this? Should I try a different approach?

Hello! I'm trying to do the same. Did you ever figure it out?
Hi Curudan and serot0nin,
I believe this could be done by creating a Composer template for the Content block. A Composer template is a way to customize the block form when displayed in Composer. Often you will see a single composer.php file in a block, with Composer templates, you can create multiple composer forms to choose from.
In the template, you would add a check to see if there was any saved content. If there was no saved content, then you would add default content.
- copy the Content block's composer.php file
concrete\blocks\content\composer.php
- in application\blocks, create a folder called "content", inside "content" create a folder called "composer"
application\blocks\content\composer
- paste composer.php into application\blocks\content\composer
application\blocks\content\composer\composer.php
- rename composer.php to your desired template name (plant_table.php)
application\blocks\content\composer\plant_table.php
- open your template (plant_table.php) and look for the line of code that creates the rich text editor:
- before this line, you will add an if check to see if $content has any saved content
- go to the Page Types page and edit the form for your page type
Dashboard > Pages & Themes > Page Types > Edit Form
- add the Content block
- after adding the Content block, edit the block's form control, and then choose "Plant Table" from the Custom Template drop-down
Example: plant_table.php
When applied to the Content block, if there is no saved value, the default will be table HTML and text.
@Curudan
For your particular situation, I think the better choice would be to use custom page attributes. You could then add PHP in your page template to create the table for you. This has the advantage of allowing you to have full control over the output (there isn't the risk of a user adding non-standard formatting or styling).
I believe this could be done by creating a Composer template for the Content block. A Composer template is a way to customize the block form when displayed in Composer. Often you will see a single composer.php file in a block, with Composer templates, you can create multiple composer forms to choose from.
In the template, you would add a check to see if there was any saved content. If there was no saved content, then you would add default content.
- copy the Content block's composer.php file
concrete\blocks\content\composer.php
- in application\blocks, create a folder called "content", inside "content" create a folder called "composer"
application\blocks\content\composer
- paste composer.php into application\blocks\content\composer
application\blocks\content\composer\composer.php
- rename composer.php to your desired template name (plant_table.php)
application\blocks\content\composer\plant_table.php
- open your template (plant_table.php) and look for the line of code that creates the rich text editor:
echo Core::make('editor')->outputPageComposerEditor($view->field('content'), $content);
- before this line, you will add an if check to see if $content has any saved content
- go to the Page Types page and edit the form for your page type
Dashboard > Pages & Themes > Page Types > Edit Form
- add the Content block
- after adding the Content block, edit the block's form control, and then choose "Plant Table" from the Custom Template drop-down
Example: plant_table.php
<?php defined('C5_EXECUTE') or die("Access Denied."); ?> <div class="form-group"> <label><?=$label?></label> <?php if ($description): ?> <i class="fa fa-question-circle launch-tooltip" title="" data-original-title="<?=$description?>"></i> <?php endif; ?> <?php $content = $controller->getContentEditMode(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $data = $view->getRequestValue(); $content = $data['content']; } if (!$content) { $content = <<<EOD <table>
Viewing 15 lines of 33 lines. View entire code block.
When applied to the Content block, if there is no saved value, the default will be table HTML and text.
@Curudan
For your particular situation, I think the better choice would be to use custom page attributes. You could then add PHP in your page template to create the table for you. This has the advantage of allowing you to have full control over the output (there isn't the risk of a user adding non-standard formatting or styling).
Fab stuff, MrKDilkington.
As it happens, I was wondering how composer templates work, but hadn't delved into them just yet. Thank you for the detailed and very helpful explanation. Anyway, in the end, I've opted for a custom page attribute. The idea of checking for content before rendering the editor will surely come in handy as well.
Again, many thanks!
As it happens, I was wondering how composer templates work, but hadn't delved into them just yet. Thank you for the detailed and very helpful explanation. Anyway, in the end, I've opted for a custom page attribute. The idea of checking for content before rendering the editor will surely come in handy as well.
Again, many thanks!