Layouts and Blocks
The step-by-step guide has already covered the most common method for accessing static views. However, I'll reiterate and introduce some additional approaches.
Two view type
There are 2 types of views in Stratox which you will mostly use:
Layout: Is the starting point and main view that is initlized in the controller.
Block: Extens layout view with blocks of content. Block view is also a self-contained and dynamic component, meaning it can be used to easily update its content without having to update the whole layout!
NOTE: The Layout and block method can be initialized the same way but just has diferent names and render functionalities.
Layout - Example 1
Begin by importing the view:
Once imported, you're ready to display the view:
This code imports the "Ingress" view and displays it with the specified headline and content.
The view
object argument is the main view instance while item
is the view context. Both can be used to update or add data to the layout, but in most cases, you can manage without them since they are also accessible inside the layout view.
Loading the Same Layout Multiple Times
You can load the same view multiple times by providing unique names for each instance. Here's how you can do it:
What makes Layout unique is that it is loaded in the controller and can be loaded multiple times. Stratox automatically appends them sequentially. This example above also works with the same component and also with block, by appending a unique identifier before the layout function (e.g., ingressView1, ingressView2), you can load the same layout with different data. This approach allows for efficient reuse of views throughout your application.
Layout - Example 2
In most cases, it's recommended to import the view, as it helps organize your code effectively. However, there are scenarios where you might only need to add a small HTML component without the need for separate files. In such cases, you can directly define the view within your code.
We'll demonstrate the "Loading the Same View Multiple Times" approach directly in this example. This method also allows you to name the view, enabling dynamic changes to the view data after loading.
In this example, we define the layouts directly within the code, specifying unique names for each view. The provided data is then dynamically rendered within the view components.
NOTE: The block method can be initialized the same as layout.
Block - Example
You utilize blocks to extend your layouts with dynamic block components, this could be everyting from a table with sotable data to a modal.
So it is not harder than starting with a layout
view and extend the layout with block
views.
Component argumnets
props
This is the object data passed to your template file. It contains information that helps to render the view with dynamic data
container
The container can be used to communicate with your template and the outside. You can create your own or access the frameworks functions like bellow.
helper
Your own possible helper libraries, objects, and functions you passed in the configuration.
context
Access the Stratox builder context library (you can manage without, only for advanced users; more on this later on).
Last updated