- concrete5 Cookbook
- David Strack
- 181字
- 2021-08-13 16:16:01
Including JavaScript in the block view
In addition to being able to include JavaScript in the block's add and edit forms, developers can also automatically include a JavaScript file when the block is viewed on the frontend. In this recipe, we will create a simple JavaScript file that will create an alert whenever the block is viewed.
Getting ready
We will continue working with the block that was created in the first recipe of this chapter.
How to do it...
The steps for including JavaScript in the block view are as follows:
- Open your block's directory.
- Create a new file called
view.js
. - Add an alert to
view.js
:alert('This is the view!');
- Visit the page containing your block.
- You should see the new alert appear.
How it works...
Much like the auto.js
file discussed in the previous recipe, concrete5 will automatically include the view.js
file if it exists. This allows developers to easily embed jQuery plugins or other client-side logic into their blocks very easily.
See also
- The Including JavaScript in block forms recipe
- The Including CSS in the block view recipe
推薦閱讀
- Unity 2020 By Example
- CockroachDB權(quán)威指南
- C語言程序設(shè)計(jì)教程(第2版)
- Django Design Patterns and Best Practices
- Python高級(jí)編程
- 蘋果的產(chǎn)品設(shè)計(jì)之道:創(chuàng)建優(yōu)秀產(chǎn)品、服務(wù)和用戶體驗(yàn)的七個(gè)原則
- Mockito Essentials
- 零基礎(chǔ)學(xué)C語言(升級(jí)版)
- 零基礎(chǔ)學(xué)C語言(第4版)
- Java自然語言處理(原書第2版)
- Swift High Performance
- Splunk Essentials
- Python滲透測(cè)試編程技術(shù):方法與實(shí)踐(第2版)
- Python繪圖指南:分形與數(shù)據(jù)可視化(全彩)
- INSTANT Lift Web Applications How-to