- 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
推薦閱讀
- GraphQL學(xué)習(xí)指南
- 微服務(wù)與事件驅(qū)動(dòng)架構(gòu)
- JavaScript:Functional Programming for JavaScript Developers
- Java虛擬機(jī)字節(jié)碼:從入門到實(shí)戰(zhàn)
- Learning Firefox OS Application Development
- 深入RabbitMQ
- 低代碼平臺(tái)開發(fā)實(shí)踐:基于React
- OpenCV with Python By Example
- Learning JavaScript Data Structures and Algorithms(Second Edition)
- 從Excel到Python數(shù)據(jù)分析:Pandas、xlwings、openpyxl、Matplotlib的交互與應(yīng)用
- Python網(wǎng)絡(luò)爬蟲實(shí)例教程(視頻講解版)
- C/C++代碼調(diào)試的藝術(shù)(第2版)
- Improving your Penetration Testing Skills
- Elasticsearch實(shí)戰(zhàn)(第2版)
- Learning ClojureScript