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

  • 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
主站蜘蛛池模板: 沈阳市| 嘉鱼县| 富蕴县| 岳西县| 镇原县| 两当县| 汕尾市| 灵璧县| 宁南县| 渝北区| 汤阴县| 固安县| 陆丰市| 乌兰县| 巴里| 公安县| 名山县| 麻江县| 黄石市| 伊金霍洛旗| 西吉县| 皮山县| 北川| 石泉县| 汉沽区| 溧阳市| 绥化市| 祁东县| 静安区| 镇宁| 延庆县| 铜陵市| 平湖市| 吉林省| 南京市| 鲜城| 德江县| 仁化县| 曲靖市| 常宁市| 琼海市|