Sage9 Template & Wrapper

I want to get a specific template file rendered/populated through Blade.
In the class, I need to replace the (old?) (new Template(new Wrapper($template)))->layout(); to something that works with the latest Sage9

My template path seems correct (using locate_template); however I tried with both template_include filter and echo App\template(): both seems to interpret PHP just fine but output any blade statements without interpreting them i.e. raw text outputs appear in the page like “@extends(‘’)”; there must be something I’m doing that is wrong :slight_smile:

How can I render the page?

Pasting from the Sage book:

Rendering Blade templates from PHP (eg. hooks/actions and filters)

Find yourself needing to render a Blade template with PHP? Use the template helper function available in the App namespace.

Here’s an example of adding a [reviews] shortcode that renders the partials/reviews.blade.php file:

add_shortcode('reviews', function($atts) {
    return \App\template('');

Thanks @ben I will be focusing on the App\template then

I’m using Cortex to set custom routes; it seems awesome but I must be doing something wrong somewhere and it’s probably down to my poor understanding :persevere:

I replaced $template = (new Template(new Wrapper($tmpl)))->layout();

 $tmpl_location = locate_template('views/'.$tmpl.'.blade.php');
 $template = App\template($tmpl_location);

It now shows a page withe the element but no css and overrides my custom templates to render the custom query.
When I output what the helpers’ template function received: it shows the $file twice for a single request; the first output looks good (it’s my custom template file location); the second time it reverts to the default index.blade.php

I should probably look into Cortex more to better understand how this works.

Btw, the book along the blog, discourse and the slack chan are such precious tools to learn more; my brain felt a joyful overdrive trying to pierce the logic to render templates. Thank you so much for all the work!

Actually it seems to be hitting the \App\template twice all the time – on a distinct (default front page) url, without the Cortex loaded.

Turns out it was pretty simple to sort the Brain/Cortex issue in the first place:
do not use the custom template parameter ¯_(ツ)_/¯

Thanks to @alwaysblank for updating his answers

Hello Jerome,

First of all I apologize for my English level, I hope we can understand each other.

I have the same problem as you, the solution proposed in the thread,

it does not work for versions 9.1. * of Sage, but I do not understand the solution proposed by @alwaysblank, did it finally work for you? How did you do it?

Thanks in advance,

Hey Zacarias, sorry I missed the thread on Github
this is the route that worked in the end—as you can see it doesn’t use a custom template, just the normal route and Sage will pick up the template based on the post type. Hope this helps!

$routes->addRoute(new QueryRoute(
  function(array $matches) {
    $airing_year = $matches['year'];
    return [
      'numberposts' => -1,
      'post_type'   => 'po_te_films',
      'meta_query' => array(
            'key'    => 'air_date',
            'value'  => $airing_year,
            'compare' => 'LIKE',