Xgenious/ docs
Products
Get support

Context API — Overview

Inspired by WordPress template tags, the Context API provides typed wrapper objects automatically injected into the right views. Theme developers work with clean method calls — never raw Eloquent models or array keys.

Note

ℹ️ ℹ How injection works BlogComposer is registered for all blog::* views and ShopComposer for all theme::frontend.shop.* views. They run automatically and inject $theme_* Blade variables. You can also call the equivalent helper functions anywhere.

Warning

⚠️ ⚠ Provider boot order — blog sidebar data ThemeServiceProvider (an app provider) boots before BlogServiceProvider (a module provider), so BlogComposer runs before the module's own blog::* view composer. As a result, BlogComposer does not rely on $data['all_category'] being passed by the controller. It self-fetches BlogCategory and BlogTag directly from the database using a !View::shared() guard to avoid duplicate queries. Implication: theme_blog_categories() and theme_blog_tags() always return data on every blog::* view with no controller changes. If sidebar data is missing, the fix belongs in BlogComposer, not in individual controllers.

Two ways to access the same data:

// Option A — Blade variable (injected by composer)
@foreach($theme_blogs as $post)
    {{ $post->title() }}
@endforeach

// Option B — Helper function (works anywhere, even in partials)
@foreach(theme_blogs() as $post)
    {{ $post->title() }}
@endforeach

Blog Context

Available in all blog::* views (list, single, category, search).

Variable / FunctionTypeAvailable inDescription
$theme_blogs / theme_blogs()Collection<Blog\Post>blog-all, blog-category, blog-searchCurrent page posts as Post wrappers
$theme_blogs_paginator / theme_blogs_paginator()LengthAwarePaginatorblog-all, blog-categoryRaw paginator for ->links()
$theme_post / theme_post()Blog\Postblog-singleCurrent post wrapper
$theme_comments / theme_comments()Collection<Blog\Comment>blog-singleTop-level comments
$theme_comments_count / theme_comments_count()intblog-singleTotal comment count
$theme_blog_categories / theme_blog_categories()Collection<Blog\Category>all blog viewsSidebar categories
$theme_blog_tags / theme_blog_tags()Collection<Blog\Tag>all blog viewsSidebar tags

Shop Context

Available in all theme::frontend.shop.* views.

Variable / FunctionTypeAvailable inDescription
$theme_products / theme_products()Collection<Shop\Product>shop listingCurrent page products
$theme_product / theme_product()Shop\Productproduct detailCurrent product wrapper
$theme_related_products / theme_related_products()Collection<Shop\Product>product detailRelated products
$theme_shop_categories / theme_shop_categories()Collection<Shop\ProductCategory>shop listingSidebar categories
Still stuck?
Our support team is ready to help you get set up.
Get support