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

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
主站蜘蛛池模板: 民勤县| 永嘉县| 新晃| 苍溪县| 曲靖市| 旺苍县| 惠东县| 湖南省| 海阳市| 瑞安市| 丹东市| 罗江县| 铁力市| 吴忠市| 九江市| 巴彦淖尔市| 穆棱市| 汶川县| 合肥市| 社会| 东光县| 许昌县| 时尚| 周宁县| 西吉县| 元氏县| 河津市| 鱼台县| 正阳县| 和平县| 长阳| 海淀区| 无极县| 柏乡县| 通辽市| 麻江县| 乌兰县| 阿瓦提县| 昭觉县| 栖霞市| 东宁县|