Adding a Designer Content block to a page type by default

Permalink Browser Info Environment
I've created a block using Designer Content (in c56) which works fine when added to a page in the normal way to add a block. I now want to create a page type which contains that block by default so I've taken an existing page type and changed

$a = new Area('Main');
$a->setBlockLimit(1);
$a->display($c);


to
$pub = BlockType::getByHandle('publication');
$pub->controller->field_1_textbox_text = ''; // Title *
$pub->controller->field_2_image_fID = 0; // Cover image *
$pub->controller->field_3_wysiwyg_content = ''; // description *
$pub->controller->field_4_textarea_text = ''; // Publisher name & address *
$pub->controller->field_5_link_url = ''; // email
$pub->controller->field_6_link_url = ''; // website
$pub->controller->field_7_file_fID = 0; // optional download link 1
$pub->controller->field_8_file_fID = 0; // optional download link 2
$pub->render('view');


* These fields are required

But it doesn't display the block and I can't edit the block contents.
I get the field names from the block controller

I did try to add the block to the page type default but because there are several required fields I have would have to enter some default values when I add the block to the page type and I'd rather not do that.

Have i done something wrong or missed something out?

Thanks

Type: Pre-Sale
Status: In Progress
briggers
View Replies:
jordanlev replied on at Permalink Reply
jordanlev
I'm not sure why your code isn't working, but in general I'd recommend not hardcoding blocks into pagetype templates. Use a global area instead, and disable the editing controls on all pages except the "Page Type Defaults", so you can set it up once and not worry about the people adding/editing pages accidentally changing anything. Seehttp://concrete5tricks.com/blog/dont-hardcode-blocks-use-a-global-a...
briggers replied on at Permalink Reply
briggers
Thanks for the reply.
I did read that article and have tried it. The problem is that when one adds the block to the page if there are required fields one has to put something into those fields and that content then shows when anyone uses the page type. They then have to delete/overwrite the defaults before entering their own content and I wanted to avoid that.

Hardcoding the block into the page is the only way I can see of avoiding having default content showing - maybe there is another way I've not found. In fact I can't get any block containing a form with required fields to work. The block does not show in edit mode

At the moment I have the block added in the way you suggest without specifying the fields as required - that works, but I do lose some control over the way the page type is used.
jordanlev replied on at Permalink Reply
jordanlev
Sorry for the delay (this somehow got lost this in my inbox)...

If the problem is that you don't want default data showing up, can you just not supply any default data? That is, the block can exist on the page defaults, but all of the fields are empty?

-Jordan

concrete5 Environment Information

# concrete5 Version
5.6.3.2

# concrete5 Packages
Blueberry Image Slider (1.3), Designer Content (3.1.1), Easy News (1.2.0), FAQ Page Manager (1.0), Free Cookies Disclosure (1.0.3), Gallery (1.8.1), List files from set (1.0.4), Picmonkey Image Editor (1.00), Slate Theme (1.5.3.1).

# concrete5 Overrides
blocks/product_list, blocks/product_information, blocks/publication, blocks/protected_file, elements/files, languages/sl_SI, languages/fa_IR, languages/es_ES, languages/zh_TW, languages/pt_PT, languages/ru_RU, languages/es_PE, languages/sv_SE, languages/nb_NO, languages/tr_TR, languages/cs_CZ, languages/nl_NL, languages/vi_VN, languages/es_MX, languages/fi_FI, languages/de_DE, languages/ja_JP, languages/el_GR, languages/da_DK, languages/ar, languages/sk_SK, languages/it_IT, languages/ro_RO, languages/es_AR, languages/fr_FR

# concrete5 Cache Settings
Block Cache - Off
Overrides Cache - Off
Full Page Caching - Off

# Server Software
Apache/2.4.7 (Ubuntu)

# Server API
apache2handler

# PHP Version
5.5.9-1ubuntu4.5

# PHP Extensions
apache2handler, bcmath, bz2, calendar, Core, ctype, curl, date, dba, dom, ereg, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, imagick, json, libxml, mbstring, mcrypt, mhash, mysql, mysqli, odbc, openssl, pcre, PDO, pdo_mysql, PDO_ODBC, pdo_sqlite, Phar, posix, pspell, readline, Reflection, sasl, session, shmop, SimpleXML, soap, sockets, SPL, sqlite3, standard, sysvmsg, sysvsem, sysvshm, tidy, tokenizer, wddx, xdebug, xml, xmlreader, xmlwriter, xsl, Zend OPcache, zip, zlib.

# PHP Settings
max_execution_time - 30
log_errors_max_len - 1024
max_file_uploads - 20
max_input_nesting_level - 64
max_input_time - 120
max_input_vars - 1000
memory_limit - 256M
post_max_size - 8M
sql.safe_mode - Off
upload_max_filesize - 5M
mysql.max_links - Unlimited
mysql.max_persistent - Unlimited
mysqli.max_links - Unlimited
mysqli.max_persistent - Unlimited
odbc.max_links - Unlimited
odbc.max_persistent - Unlimited
pcre.backtrack_limit - 1000000
pcre.recursion_limit - 100000
session.cache_limiter - nocache
session.gc_maxlifetime - 7200
soap.wsdl_cache_limit - 5
xdebug.max_nesting_level - 100
xdebug.var_display_max_children - 128
xdebug.var_display_max_data - 512
xdebug.var_display_max_depth - 3
opcache.max_accelerated_files - 2000
opcache.max_file_size - 0
opcache.max_wasted_percentage - 5

Browser User-Agent String

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.