Increment / Events
Let's make the About page more interactive by adding a simple "click and increment" feature. Each click will update the displayed count, showing how many times the button has been clicked.
Create Your View
First, create a new view template file named templates/views/blocks/Increment.js
. Define the view function as follows:
Note: We created a new view in the directory blocks
. Although the increment view can function like any other view, we intend to use it specifically as a block view. This means we will extend a view—specifically, the start view—with the increment.
Quick Breakdown
Event Binding: We start by binding the click function to a constant named
clickEvent
, which will execute when the button is clicked.Triggering the Event: We call
clickEvent
in the button'sonclick
attribute, triggering the function whenever the button is clicked, updating the counter and headline dynamically.
Note: It will work exactly the same for onchange
, oninput
, and other DOM events.
Controller
Now that we have our increment block view, we need to render it in the start view:
Visit your browser to see the results!
Summary
With these modifications, the code appears much cleaner and highly modular. You've now familiarized yourself with the Stratox architecture, and every example in this tutorial serves an essential purpose. You're free to utilize them as you see fit for your application.
Last updated