Views & components
Template Views/components
MaplePHP comes with a couple of pre-installed views/components to get you started.
Pre-installed views/components
MaplePHP will get new views/components over time. By updating the packges with the command below in your command line, will ensure you get all newly added components.
Also, make sure that the view is pre-loaded in your "resources/js/main.js" file. You can read more about it below.
Create view/component
It is super easy to create a custom view and template. Let's start by creating a new and custom ingress view.
1. Create custom view
Start by creating a new "ingress.js" file in the directory "resources/views/jviews/". (For example, there should already exist an example "ingress.js" file at that location; if not, just create it and add the code below.)
The component could look something like bellow.
2. Import view/component
Then open up your "resources/js/main.js" file and import the "ingress.js" template file directly under the last imported file.
Set the component/view inside the setup
object function in the "main.js" file by adding Stratox.setComponent("ingress", ingressComponent)
:
Your dynamic view/component is now ready to be used.
Set view
To display a dynamic view or content, you just need to execute the code below in, for example, your controller. It will dynamically create an ingress view inside the HTML element with the ID "#yourElement" in your document. You can add the element in your index, view, or a partial file (see the template engine section); it is up to you.
Append view after view
By utilizing the $item
variable from above example and execute bellow under the ingress setView
method, it will append a dynamic table view under the ingress view.
Now above views will dynamically show on page views, which really are not that dynamically but a great option to have. Lets take a look on how to execute the views dynamically on Ajax request.
Click event
There already exists a built in event for making a Ajax request on click event.
You can place the above HTML tag anywhere in your HTML code—index, view, or partial; anywhere is fine. To execute a click Ajax request, you need to add the class "maple-get-btn" and the data attribute "data-href". We use the "data-href" attribute explicitly for the Ajax request, not the regular "href". This is because bots, e.g., Google bots, will index the "href" and not "data-href". This means you can add the same or different URL for the bots.
When the user executes the above code, it will make an Ajax request to the URL "https://example.com/about/new-slug" or whatever URL you build. If that URL is pointed to a Controller that has, for example, the controller method from the previous example above, "yourControllerMethod," it will dynamically add an ingress and table view!
Last updated