@@ -9,83 +9,83 @@ brief: Learn how to work with content in your frontend templates.
99quick_links : []
1010---
1111
12-
1312## Content Helper
1413
1514The ` inspirecms_content() ` helper provides access to content items throughout your frontend templates:
1615
1716``` php
1817// Get content by ID
19- $content = inspirecms_content()->findByIds(ids: '550e8400-e29b-41d4-a716-446655440000', limit: 1)->first();
18+ $modelContent = inspirecms_content()->findByIds(ids: '550e8400-e29b-41d4-a716-446655440000', limit: 1)->first();
2019
2120// Get content by slug
22- $content = inspirecms_content()->findByRealPath(path: 'about-us', limit: 1)->first();
21+ $modelContent = inspirecms_content()->findByRealPath(path: 'about-us', limit: 1)->first();
2322
2423// Get multiple content items
25- $contents = inspirecms_content()->findByIds(['550e8400-e29b-41d4-a716-446655440000', '7f1b96c0-d4f0-11ed-afa1-0242ac120002']);
24+ $modelContents = inspirecms_content()->findByIds(['550e8400-e29b-41d4-a716-446655440000', '7f1b96c0-d4f0-11ed-afa1-0242ac120002']);
2625
2726// Get published content under 'home'
28- $contents = inspirecms_content()->getUnderRealPath(path: 'home', isPublished: true);
27+ $modelContents = inspirecms_content()->getUnderRealPath(path: 'home', isPublished: true);
2928
3029// Get paginated published content under 'home'
31- $contents = inspirecms_content()->getPaginatedUnderRealPath(path: 'home', isPublished: true, page: 1, perPage: 10);
30+ $modelContents = inspirecms_content()->getPaginatedUnderRealPath(path: 'home', isPublished: true, page: 1, perPage: 10);
3231
3332// Get content by document type
34- $blogPosts = inspirecms_content()->getByDocumentType(documentType: 'blog_post ', isPublished: true);
33+ $modelContents = inspirecms_content()->getByDocumentType(documentType: 'blog-post ', isPublished: true);
3534
3635// Get paginated content by document type
37- $blogPosts = inspirecms_content()->getPaginatedByDocumentType(documentType: 'blog_post ', isPublished: true, page: 1, perPage: 10);
36+ $modelContents = inspirecms_content()->getPaginatedByDocumentType(documentType: 'blog-post ', isPublished: true, page: 1, perPage: 10);
3837```
3938
4039> [ !note]
4140>
4241> These functions return Content model instances. To access content properties and use them in templates, convert the model to a DTO using the ` toDto() ` method:
4342>
4443> ``` php
45- > $contentDto = $content->toDto($locale ?? app()->getLocale());
44+ > $contentDto = $moedlContent->toDto($locale ?? app()->getLocale());
45+ >
4646> $title = $contentDto->getTitle();
4747> ```
4848
4949---
5050
51- ## Accessing Content Properties
51+ ## Accessing ContentDTO Properties
5252
5353### Basic Properties
5454
5555Access core content attributes:
5656
5757```php
58- $title = $content ->getTitle(); // Get content title
59- $slug = $content ->slug; // Get content slug
60- $url = $content ->getUrl(); // Get content URL
61- $locale = $content ->getLocale(); // Get content locale
62- $publishedAt = $content ->publishAt; // Publication date
58+ $title = $contentDto ->getTitle(); // Get content title
59+ $slug = $contentDto ->slug; // Get content slug
60+ $url = $contentDto ->getUrl(); // Get content URL
61+ $locale = $contentDto ->getLocale(); // Get content locale
62+ $publishedAt = $contentDto ->publishAt; // Publication date
6363```
6464
6565### Custom Fields
6666
6767Use property directives in Blade templates to access custom fields:
6868
6969``` php
70- <!-- Single property -->
70+ // Single property
7171<h1 >@property('hero', 'title')</h1 >
7272
73- <!-- With custom variable name -->
73+ // With custom variable name
7474@property('hero', 'images', 'custom_images')
7575@foreach($custom_images ?? [] as $image)
7676 <img src =" {{ $image->getUrl() }}" >
7777@endforeach
7878
79- <!-- Value is from $blogDTO, variable available as $blog_category -->
79+ // Value is from $blogDTO, variable available as $blog_category
8080@property('blog', 'category', null, $blogDTO)
8181
82- <!-- Array properties -->
82+ // Array properties
8383@propertyArray('gallery', 'images')
8484@foreach($gallery_images ?? [] as $image)
8585 <img src =" {{ $image->getUrl() }}" alt =" {{ $image->alt_text }}" >
8686@endforeach
8787
88- <!-- Conditional display -->
88+ // Conditional display
8989@propertyNotEmpty('hero', 'button_text')
9090 <a href =" @property('hero', 'button_link')" class =" btn" >
9191 {{ $hero_button_text }}
@@ -97,21 +97,21 @@ You can also access properties programmatically:
9797
9898``` php
9999// Check if property exists
100- if ($content ->hasProperty('hero', 'title')) {
100+ if ($contentDto ->hasProperty('hero', 'title')) {
101101 // Get property value
102- $title = $content ->getPropertyValue('hero', 'title');
102+ $title = $contentDto ->getPropertyValue('hero', 'title');
103103
104104 // Get property value with fallback
105- $subtitle = $content ->getPropertyValue('hero', 'subtitle') ?? 'Default subtitle';
105+ $subtitle = $contentDto ->getPropertyValue('hero', 'subtitle') ?? 'Default subtitle';
106106
107107 // Get multilingual property with specific locale
108- $frenchTitle = $content ->getPropertyValue('hero', 'title', 'fr');
108+ $frenchTitle = $contentDto ->getPropertyValue('hero', 'title', 'fr');
109109}
110110
111111// Check if property group exists
112112if ($content->hasPropertyGroup('hero')) {
113113 // Get entire property group
114- $heroGroup = $content ->getPropertyGroup('hero');
114+ $heroGroup = $contentDto ->getPropertyGroup('hero');
115115}
116116```
117117
@@ -122,14 +122,17 @@ if ($content->hasPropertyGroup('hero')) {
122122Access related content and structure:
123123
124124``` php
125- // Get parent content
126- $parent = $content ->getParent();
125+ // Get parent contentDTO
126+ $parent = $contentDto ->getParent();
127127
128- // Get all child content
129- $children = $content->getChildren();
128+ // Get all child contentDTO
129+ $children = $contentDto->getChildren();
130+
131+ // Get paginated child contentDTO (After v1.1.x)
132+ $paginator = $contentDto->getPaginatedChildren(page: 1, perPage: 15, pageName: 'page2', isWebPage: true, isPublished: true, sorting: ['__latest_version_publish_dt' => 'desc'])
130133
131134// Get ancestors in hierarchical order
132- $ancestors = $content ->getAncestors();
135+ $ancestors = $contentDto ->getAncestors();
133136```
134137
135138---
@@ -140,15 +143,15 @@ Filter and sort content collections:
140143
141144``` php
142145// Get recent blog posts
143- $recentPosts = inspirecms_content()->getUnderRealPath(
146+ $modelContents = inspirecms_content()->getUnderRealPath(
144147 path: 'blogs',
145148 isPublished: true,
146149 sorting: ['__latest_version_publish_dt' => 'desc'],
147150 limit: 5,
148151);
149152
150153// Get paginated recent blog posts
151- $recentPosts = inspirecms_content()->getPaginatedUnderRealPath(
154+ $modelContents = inspirecms_content()->getPaginatedUnderRealPath(
152155 path: 'blogs',
153156 page: 1,
154157 perPage: 10,
@@ -157,7 +160,7 @@ $recentPosts = inspirecms_content()->getPaginatedUnderRealPath(
157160);
158161
159162// Filter by custom fields
160- $featuredPosts = inspirecms_content()->getByDocumentType(
163+ $dtoContents = inspirecms_content()->getByDocumentType(
161164 documentType: 'blog_post',
162165 limit: 50,
163166 )
@@ -175,14 +178,11 @@ Access content in different languages:
175178
176179``` php
177180// Get content in specific language
178- $frenchContent = $contentModel->toDto('fr');
179-
180- // Check if content is available in a language
181- $hasSpanish = $content->hasTranslation('es');
181+ $frenchContentDto = $modelContent->toDto('fr');
182182
183183// Loop through all available translations
184184foreach (inspirecms()->getAllAvailableLanguages() as $locale => $langDto) {
185- $translatedTitle = $content ->getTitle($locale);
185+ $translatedTitle = $contentDto ->getTitle($locale);
186186 // Do something with the translation
187187}
188188```
@@ -195,15 +195,15 @@ Paginate content collections:
195195
196196``` php
197197// In your controller
198- $paginatedContent = inspirecms_content()->getPaginatedByDocumentType(documentType: 'blog_post ', perPage: 10);
198+ $paginatedContentDto = inspirecms_content()->getPaginatedByDocumentType(documentType: 'post-page ', perPage: 10)->toDto( );
199199
200200// In your Blade template
201- @foreach ($paginatedContent as $post)
201+ @foreach ($paginatedContentDto as $post)
202202 <h2 >{{ $post->getTitle() }}</h2 >
203203 <p >{{ $post->getPropertyValue('blog', 'excerpt') }}</p >
204204@endforeach
205205
206- {{ $paginatedContent ->links() }}
206+ {{ $paginatedContentDto ->links() }}
207207```
208208
209209---
0 commit comments