@@ -4,7 +4,7 @@ InspireCMS leverages Laravel's powerful Blade templating engine to create dynami
44
55## Introduction to Blade
66
7- Blade is Laravel's templating engine that combines the simplicity of plain PHP with powerful features like template inheritance, components, and directives. In InspireCMS, Blade is used to build flexible and maintainable templates for your website.
7+ [ Blade] ( https://laravel.com/docs/11.x/blade ) is Laravel's templating engine that combines the simplicity of plain PHP with powerful features like template inheritance, components, and directives. In InspireCMS, Blade is used to build flexible and maintainable templates for your website.
88
99### Basic Blade Syntax
1010
@@ -60,7 +60,7 @@ Access array properties:
6060``` php
6161@propertyArray('gallery', 'images')
6262@foreach($gallery_images ?? [] as $image)
63- <img src =" {{ $image->getUrl() }}" alt =" {{ $image->alt_text }}" >
63+ <img src =" {{ $image->getUrl() }}" alt =" {{ $image->caption }}" >
6464@endforeach
6565```
6666
@@ -76,36 +76,6 @@ Conditionally display content when a property has a value:
7676@endif
7777```
7878
79- ### Navigation Directives
80-
81- Render navigation menus:
82-
83- ``` php
84- @navigationMenu('main', ['class' => 'main-nav', 'id' => 'primary-menu'])
85- ```
86-
87- Customize with a callback:
88-
89- ``` php
90- @navigationMenu('main', function($items) {
91- echo '<ul class =" main-nav" >';
92- foreach ($items as $item) {
93- echo '<li ><a href =" ' . $item->getUrl() . '" >' . $item->getTitle() . '</a >';
94-
95- if ($item->hasChildren()) {
96- echo '<ul class =" sub-menu" >';
97- foreach ($item->children as $child) {
98- echo '<li ><a href =" ' . $child->getUrl() . '" >' . $child->getTitle() . '</a ></li >';
99- }
100- echo '</ul >';
101- }
102-
103- echo '</li >';
104- }
105- echo '</ul >';
106- })
107- ```
108-
10979### Language and Localization Directives
11080
11181Display content in multiple languages:
@@ -175,13 +145,13 @@ Create custom theme components:
175145Use your component:
176146
177147``` php
178- <x-inspirecms-my-theme:: alert type =" warning" title =" Important Notice" >
148+ <x-dynamic-component :component = " inspirecms_templates()->getComponentWithTheme(' alert') " type =" warning" title =" Important Notice" >
179149 This is an important message for all users.
180150
181151 <x-slot:footer >
182152 <button >Dismiss</button >
183153 </x-slot >
184- </x-inspirecms-my-theme::alert >
154+ </x-dynamic-component >
185155```
186156
187157## Blade Layouts and Template Inheritance
@@ -370,7 +340,7 @@ Work with collections and arrays:
370340
371341``` php
372342@propertyArray('blog', 'related_posts')
373- @forelse($blog_related_posts as $post)
343+ @forelse($blog_related_posts ?? [] as $post)
374344 <div class =" related-post" >
375345 <h3 ><a href =" {{ $post->getUrl() }}" >{{ $post->getTitle() }}</a ></h3 >
376346 <p >{{ Str::limit($post->getPropertyValue('blog', 'excerpt'), 100) }}</p >
@@ -385,7 +355,7 @@ Use the `@foreach` directive with loop variable:
385355``` php
386356@foreach($gallery_images as $image)
387357 <div class =" gallery-item {{ $loop->first ? 'first' : '' }} {{ $loop->last ? 'last' : '' }}" >
388- <img src =" {{ $image->getUrl() }}" alt =" {{ $image->alt_text }}" >
358+ <img src =" {{ $image->getUrl() }}" alt =" {{ $image->caption }}" >
389359 <span class =" number" >{{ $loop->iteration }}/{{ $loop->count }}</span >
390360 </div >
391361@endforeach
@@ -418,9 +388,9 @@ class BladeServiceProvider extends ServiceProvider
418388 Blade::directive('contentLink', function ($expression) {
419389 $params = explode(',', $expression);
420390 $id = trim($params[0]);
421- $text = isset($params[1]) ? trim($params[1]) : 'null';
422-
423- return "<?php echo inspirecms_content_link( $id, $text ); ?>";
391+ $locale = isset($params[1]) ? trim($params[1]) : 'null';
392+
393+ return "<?php echo inspirecms_content()->findByIds(ids: $id, limit: 1)?->getUrl($locale ); ?>";
424394 });
425395 }
426396}
@@ -431,7 +401,7 @@ Use custom directives:
431401``` php
432402<p >Posted on @formatDate($content->published_at)</p >
433403
434- <a href =" @contentLink('550e8400-e29b-41d4-a716-446655440000', 'Read our about page ')" >
404+ <a href =" @contentLink('550e8400-e29b-41d4-a716-446655440000', 'en ')" >
435405 <!-- Link content -->
436406</a >
437407```
@@ -474,42 +444,6 @@ $cacheTtl = 60 * 24; // 24 hours in minutes
474444@endcache
475445```
476446
477- ## Testing Templates
478-
479- Test your Blade templates to ensure they render correctly:
480-
481- ``` php
482- namespace Tests\Feature;
483-
484- use Tests\TestCase;
485- use SolutionForest\InspireCms\Models\Content;
486-
487- class PageTemplateTest extends TestCase
488- {
489- /** @test */
490- public function it_renders_page_template_correctly()
491- {
492- // Create a test content record
493- $content = Content::factory()->create([
494- 'title' => json_encode(['en' => 'Test Page']),
495- 'slug' => 'test-page',
496- 'status' => 1, // Published
497- ]);
498-
499- // Add content properties
500- $content->setPropertyValue('hero', 'title', 'Test Hero Title');
501-
502- // Visit the page
503- $response = $this->get($content->getUrl());
504-
505- // Assert response and content
506- $response->assertStatus(200);
507- $response->assertSee('Test Hero Title');
508- $response->assertSee('Test Page');
509- }
510- }
511- ```
512-
513447## Common Blade Patterns in InspireCMS
514448
515449### SEO Meta Tags
@@ -592,13 +526,8 @@ Implement breadcrumb navigation:
592526
593527``` php
594528@php
595- $breadcrumbs = [];
596- $current = $content;
597-
598- while ($current) {
599- array_unshift($breadcrumbs, $current);
600- $current = $current->parent;
601- }
529+ $breadcrumbs = $content->getAncestors()->toArray();
530+ $breadcrumbs[] = $content;
602531@endphp
603532
604533<nav aria-label =" Breadcrumb" >
@@ -698,8 +627,7 @@ $locale = app()->getLocale();
698627$fallbackLocale = config('app.fallback_locale');
699628
700629// Get title in current language or fallback to default language
701- $title = $content->getPropertyValue('hero', 'title', null, $locale)
702- ?? $content->getPropertyValue('hero', 'title', null, $fallbackLocale)
630+ $title = $content->getPropertyValue('hero', 'title', $locale, $fallbackLocale)
703631 ?? 'Default Title';
704632@endphp
705633
@@ -850,7 +778,7 @@ Use helpers in templates:
850778``` php
851779<p class =" post-meta" >
852780 Published on
853- <time datetime =" {{ $content->published_at->format('Y-m-d') }}" >
781+ <time datetime =" {{ $content->published_at? ->format('Y-m-d') }}" >
854782 {{ format_content_date($content->published_at) }}
855783 </time >
856784 &bull ; {{ get_reading_time($content->getPropertyValue('blog', 'body')) }} min read
0 commit comments