# How to render a blade template from filter function

**URL:** https://discourse.roots.io/t/how-to-render-a-blade-template-from-filter-function/10877
**Category:** sage
**Tags:** sage9, blade
**Created:** 2017-11-10T22:12:41Z
**Posts:** 4
**Showing post:** 2 of 4

## Post 2 by @Webstractions — 2017-11-10T22:40:30Z

@pascallaliberte Maybe this answer to an infinite-scroll topic might help?

> [@Roots Sage with Jetpack Infinite Scroll](https://discourse.roots.io/t/roots-sage-with-jetpack-infinite-scroll/10007/2):
>
> This is how I got it working on one recent site. I had to use the “render” callback function to iterate through the loop and use sage (9) template function. I hope it helps you figure it out! // Add support for Jetpack's Infinite Scroll add\_theme\_support('infinite-scroll', ['container' =\> 'main', 'footer' =\> false, 'type' =\> 'scroll', 'wrapper' =\> false, 'posts\_per\_page' =\> 12, 'render' =\> \_\_NAMESPACE\_\_ . '\\infinite\_scroll',]); …

Another route is to use the `@inject` directive to inject your service into the Blade view. This directive does not work for Sage9 because the directive looks for the `app()` helper from Laravel. You will need to overwrite it via `setup.php` like this:

```
/**
     * Overwrite @inject() Blade directive
     * IMPORTANT: This needs to follow the binding of the Blade Provider above.
     */
    sage('blade')->compiler()->directive('inject', function($expression) {
        $segments = explode(',', preg_replace("/[\(\)\\\"\']/", '', $expression));
        $variable = trim($segments[0]);
        $service = trim($segments[1]);
        return "<?php \${$variable} = App\sage('{$service}'); ?>";
    });
```

---

_[View the full topic](https://discourse.roots.io/t/how-to-render-a-blade-template-from-filter-function/10877)._
