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

  • 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:

  1. Open your block's directory.
  2. Create a new file called view.js.
  3. Add an alert to view.js:
    alert('This is the view!');
  4. Visit the page containing your block.
  5. 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
主站蜘蛛池模板: 广平县| 千阳县| 五原县| 岳阳市| 沾益县| 宁强县| 耒阳市| 巴彦县| 凉山| 潮州市| 新田县| 扶沟县| 象山县| 西安市| 利辛县| 拜城县| 绥芬河市| 安新县| 南康市| 玛沁县| 壶关县| 建湖县| 安乡县| 天等县| 湘阴县| 南丰县| 龙口市| 惠东县| 定西市| 辽宁省| 建湖县| 平泉县| 贺兰县| 榆林市| 仁化县| 衡山县| 岳阳市| 亳州市| 石景山区| 故城县| 同德县|