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

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
主站蜘蛛池模板: 大石桥市| 武宁县| 新和县| 平塘县| 兴国县| 河池市| 广宗县| 太康县| 丹东市| 屯昌县| 平顺县| 长葛市| 尼玛县| 伊川县| 苏州市| 永嘉县| 温州市| 西青区| 长子县| 隆尧县| 沽源县| 南投市| 龙胜| 肇源县| 高密市| 湛江市| 峨边| 崇文区| 阜康市| 南部县| 岑巩县| 师宗县| 安化县| 图们市| 东海县| 福州市| 衡水市| 凉山| 通山县| 金塔县| 周口市|