- concrete5 Cookbook
- David Strack
- 269字
- 2021-08-13 16:16:01
Creating custom block templates
All blocks come with a default view template, view.php
. concrete5 also supports alternative templates, which users can enable through the concrete5 interface. You can also enable these alternative templates through your custom PHP code.
Getting ready
You will need a block type created and installed already. In this recipe, we are going to add a template to the block type that we created at the beginning of the chapter.
How to do it...
The steps for creating custom block templates are as follows:
- Open your block's directory.
- Create a new directory in your block's directory called
templates/
. - Create a file called
no_title.php
intemplates/
. - Add the following HTML code to
no_title.php
:<div class="content"> <?php echo $content ?> </div>
- Activate the template by visiting a page that contains this block.
- Enter edit mode on the page and click on the block.
Click on "Custom Template".
- Choose "No Title" and save your changes.
There's more...
You can specify alternative templates right from the block controller, so you can automatically render a different template depending on certain settings, conditions, or just about anything you can think of. Simply use the render()
function in a callback that gets called before the view is rendered.
public function view() { $this->render('templates/no_title'); }
This will use the no_title.php
file instead of view.php
to render the block. Notice that adding the .php
file extension is not required. Just like the block's regular view.php
file, developers can include view.css
and view.js
files in their template directories to have those files automatically included on the page.
See also
- The Using block controller callback functions recipe
- The Creating a custom block type recipe
- Vue.js 3.x快速入門
- R語言數(shù)據(jù)分析從入門到精通
- AWS Serverless架構(gòu):使用AWS從傳統(tǒng)部署方式向Serverless架構(gòu)遷移
- 數(shù)據(jù)庫系統(tǒng)原理及MySQL應(yīng)用教程
- Android 9 Development Cookbook(Third Edition)
- Data Analysis with IBM SPSS Statistics
- 零基礎(chǔ)學(xué)Java程序設(shè)計
- 重學(xué)Java設(shè)計模式
- H5頁面設(shè)計:Mugeda版(微課版)
- 零基礎(chǔ)Java學(xué)習(xí)筆記
- GameMaker Essentials
- CRYENGINE Game Development Blueprints
- Scratch·愛編程的藝術(shù)家
- 交互式程序設(shè)計(第2版)
- C# 7.1 and .NET Core 2.0:Modern Cross-Platform Development(Third Edition)