Please keep in mind that the template inheritance in Contao 3 is pretty minimalistic due to historic reasons and not to be compared with the flexibility another engine i.e. twig (to which we are moving in Contao 4 to).
To answer your question:
You can define own blocks in your templates which can then be overridden in a child template.
In fact, every block is "created" in the "root" template of it's name and then overridden, to see this in action refer to the form element templates for example see the code of form_row.html5:
// ... code omitted, refer to linked file.
<div class="<?= $this->prefix ?><?php if ($this->class) echo ' ' . $this->class; ?>">
<?php $this->block('label'); ?>
<?php $this->endblock(); ?>
<?php $this->block('field'); ?>
<?php $this->endblock(); ?>
</div>
// ... code omitted, refer to linked file.
The blocks are introduced here and overridden in form_radio.html5:
<?php $this->extend('form_row'); ?>
<?php $this->block('field'); ?>
// ... code omitted, refer to linked file.
<?php $this->endblock(); ?>
As you can see, the block field
is being overridden and label
is not.
We can now override this block in another template again or override the label in another template extending form_radio.html5
.
As stated above, there are some limitations to be aware of:
- You are not allowed to introduce new blocks in a child template (one that uses
$this->extend()
. Doing so will end in an Exception being thrown.
- You can not introduce code outside of a block in a child template.
If there should be remaining questions, please update your question as it is a bit vague to guess what exactly you want to know.