Partials
Partials are the most commonly used template file type. If you want the same partial with identical content to appear on multiple pages, like a navigation or footer, you could create a middleware and add a partial pointer in it. For more dynamic content that is unique, such as page content or a blog post, you should add it in a controller.
To show a partial you will need to first create a partial template file in the directory resources/partials/
then you set/create a Pointer partial and a Carrot partial. The Carrot partial is only used to set a marker for where you can place a partial while the Pointer partial is used to point a partial file with content to a Carrot partial that exist somewhere in your index or view file.
Set partial
First start with the setPartial method to set a partial. The setPartial method comes with 2 arguments.
The first argument is a "key string" that is used to point to both file and carrot while the second is used to pass on content to the partial file.
The as I said the first argument is used to make a connection to both file and location to load the file it does come with some minor routing options to.
The simplest way
The "key string" in bellow example will act as a both pointer name and file meaning it expects a template file resources/partials/footer.php
to be be loaded at carrot named footer, take a look at the pointer and carrot example:
Pointer - Set partial
If you set the above partial multiple times it will overwrite the content
Carrot - Read partial
To show the partial above you just add the carrot somewhere in your index or view file.
Bind and replace content at specific carrot
You can also set a partial and bind it to a specific carrot. The "main" key string part in the bellow example will be the expected carrot name while ingress will be the expected file name resources/partials/ingress.php
and "main.ingress" will now act pointer to the partial.
If you set the above partial multiple times it will overwrite the content.
Carrot - Read partial
The ingress will be placed in main. If there already is setted content in main then that content will be replaced with the ingress.
Bind and append content at specific carrot
Works just like above with the exception that if their already is content then the partial will append after that content. The "main" key string part in the bellow example will be the expected carrot name while "ingress" key string name will be the expected file name resources/partials/ingress.php
and "welcome" will be subject and all in all "main" will act as the pointer to the partial and "welcome" as a unique identifier.
If you set the above partial multiple times it will overwrite the content but if you change the subject then the ingress will be appended under the already added ingress!
Carrot - Read partial
Partial files content
The setPartial main.ingress.*
will expect the file resources/partials/ingress.php
. It could look like bellow.
Next step we will take a deeper look a the partial content.
Last updated