This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

Changing the appearance of a block on a per-case basis is easy. You never need to modify a block's view.php in its default location, and generally this is a bad idea for reasons bigger than this how-to.

A block can be in one of three places. In order of likelihood:

  1. In the core: site_root/concrete/blocks/some_block
  2. In a package: site_root/packages/some_package/blocks/some_block/
  3. As a custom block installed on your site: site_root/blocks/some_block/

No matter where you found that block, you are going to need a folder for the new template in your site root: site_root/blocks/some_block/templates/. So unless the block was totally custom, you will need to create two folders: some_block, and templates beneath that folder.

Now to customize the block.

  1. Make a new my_template folder in your block's templates/ folder.
  2. Copy the file view.php from its original location up to blocks/some_block/templates/my_template/. If that block also has a folder called js/, copy js/ up to blocks/some_block/templates/my_template/
  3. make changes in your copy of view.php

Now on your site, you should be able to click on a block in edit mode, choose "custom template" and pick "my template". Your page should now reflect the changes made in your view.php.

You can also use this technique add fancy javascript stuff to normal blocks, and also if something seems "broken" after you've made a template, check if the block actually had a js/ folder that you missed. If your template doesn't have a js/ folder, the CMS assumes you are not trying to load any javascript.

Do you need to do something crazier? Check out overrides: right here

One other thing you are going to run into is that more elaborate blocks are going to use elements a lot. You will see something like Loader::element('element_name','package',array('data'=>"this makes data go to the element"); So what you end up having to do is override that element. When you do the override, the element can be copied, but renamed to something like my_element_name, then in your new template you will load the element my_element_name instead. By creating this new element, views that are not using your template will still look normal.

That how-to also has some good links about templates and how to use them, but this is the most basic explanation on how to create templates.

Loading Conversation