-
Book Overview & Buying
-
Table Of Contents
concrete5 Cookbook
By :
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.
We will continue working with the block that was created in the first recipe of this chapter.
The steps for including JavaScript in the block view are as follows:
Open your block's directory.
Create a new file called view.js.
Add an alert to view.js:
alert('This is the view!');Visit the page containing your block.
You should see the new alert appear.

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.
The Including JavaScript in block...
Change the font size
Change margin width
Change background colour