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

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
主站蜘蛛池模板: 武安市| 滦南县| 依兰县| 曲沃县| 敦化市| 江津市| 昂仁县| 八宿县| 波密县| 天柱县| 平塘县| 都匀市| 磴口县| 保德县| 凉山| 阿图什市| 玛曲县| 永兴县| 明水县| 宁晋县| 铜梁县| 积石山| 应城市| 连城县| 宜川县| 牙克石市| 白河县| 司法| 盐亭县| 克东县| 嘉祥县| 从江县| 于田县| 乌苏市| 鹰潭市| 汕尾市| 乡城县| 时尚| 柳河县| 凌海市| 资兴市|