官术网_书友最值得收藏!

  • concrete5 Cookbook
  • David Strack
  • 191字
  • 2021-08-13 16:16:01

Including JavaScript in block forms

When adding or editing blocks, it is often desired to include more advanced functionality in the form of client-side JavaScript. concrete5 makes it extremely easy to automatically add a JavaScript file to a block's editor form.

Getting ready

We will be working with the block that was created in the first recipe of this chapter. If you need to catch up, feel free to download the code from this book's website.

How to do it...

The steps for including JavaScript in block forms are as follows:

  1. Open your block's directory.
  2. Create a new file called auto.js.
  3. Add a basic alert function to auto.js:
    alert('Hello!');
  4. Visit a page that contains your block.
  5. Enter edit mode and edit the block.
  6. You should see your alert message appear as shown in the following screenshot:

How it works...

concrete5 automatically looks for the auto.js file when it enters add or edit mode on a block. Developers can use this to their advantage to contain special client-side functionality for the block's edit mode.

See also

  • The Including JavaScript in the block view recipe
  • The Including CSS in the block view recipe
主站蜘蛛池模板: 屯昌县| 延安市| 哈巴河县| 沈丘县| 南康市| 温泉县| 黄大仙区| 增城市| 嘉善县| 奉节县| 望都县| 满城县| 青岛市| 和龙市| 烟台市| 芜湖市| 渝北区| 东丰县| 望江县| 吉水县| 垦利县| 社旗县| 贵定县| 黔西县| 中牟县| 武穴市| 永济市| 三穗县| 云梦县| 阳谷县| 金堂县| 汽车| 南阳市| 获嘉县| 宁都县| 黄陵县| 南昌县| 阜南县| 黄浦区| 丹寨县| 长宁区|