- 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
推薦閱讀
- Deploying Node.js
- Computer Vision for the Web
- PHP 從入門到項目實踐(超值版)
- Mastering Python Scripting for System Administrators
- C語言最佳實踐
- Java Web程序設(shè)計
- Asynchronous Android Programming(Second Edition)
- Python圖形化編程(微課版)
- Unity 3D腳本編程:使用C#語言開發(fā)跨平臺游戲
- FPGA嵌入式項目開發(fā)實戰(zhàn)
- Natural Language Processing with Python Quick Start Guide
- Training Systems Using Python Statistical Modeling
- Learning Redis
- Java算法從菜鳥到達人
- Node.js核心技術(shù)教程