I am trying to use the conditional tag “is_page_template” in a Blade template that resides in partials. I’m using Sage 9 Beta 3, and I can’t figure out what to put in for the template file argument. Nothing I’ve tried has worked.
Ergo:
is_page_template(‘template-nofeat.blade.php’)
is_page_template(‘template-nofeat.php’)
is_page_template(‘nofeat.blade.php’)
is_page_template(‘nofeat.php’)
is_page_template(‘template-omfgwtf.php’)
None of that works. Just for giggles, I tried a plain is_page_template() with no argument and it worked in as much as it recognized the page does have a template applied, so I know my code is correct.
I can’t find any other posts with this question so I must be really not understanding how this Blade templating works. Can anyone help please?
When I ran the var_dump, I just got the full path of the custom template. Tried the full path which didn’t work either.
This works, but I don’t feel like it’s optimal:
/**
* Display sidebar
*/
add_filter('sage/display_sidebar', function ($display) {
static $display;
isset($display) || $display = in_array(true, [
// The sidebar will be displayed if any of the following return true
is_page()
]);
if (basename(get_page_template()) == "template-full-width.blade.php")
$display = false;
return $display;
});
I found a way guys.
Since you are in a custom page you can access to the post meta in the database and check the page template in this way {{ get_post_meta( get_the_ID(), '_wp_page_template', TRUE ) }}
and this is returning the path of the page template.
Then if you do it: {{ is_page_template('views/template-beautifulTemplateName.blade.php') }}
everything works
I’m trying to get the primary sidebar to only appear on the main blog page and single post pages. I’ve got it working fine on the single post pages with ‘is_single()’, However can’t get the other blog/posts page to show the sidebar.
The page for the posts is ‘index.blade.php’ but on every page I visit after adding ‘{!! get_page_template() !!}’ , it seems to say ‘page.blade.php’ even when the page isn’t using ‘page.blade.php’.