Create shortcode not working sage 9.0.10

I’m using sage 9.0.10. I’m having trouble creating a shortcode.
I need to create a shortcode, for a custom post type template (file archive-faqs.blade.php in folder views / partials), in the archive-faqs file I write like this. and I call the detail content in content-faqs.blade.php
(write in functions.php)
function create_shortcode() {
include \App\template(‘archive-faqs’);
$new_output = ob_get_clean();
if( !empty( $new_output ) )
return $new_output;
return ‘’;
add_shortcode( ‘test_shortcode’, ‘create_shortcode’ );

in archive-faqs.blade.php

in file partials/content-faqs.blade.php

Error: it didn’t work, I did something wrong. Help me please.
Thank you very much.

\App\template() returns a string that is the rendered version of the template; not a filepath. You can’t include it.

So how do I get it to work.? @alwaysblank
I removed the include, but it still doesn’t work.

I don’t understand what you want the shortcode to do, so I don’t know how to help you make it do what you want. If you can describe the goal you’re trying to achieve rather than how the tools you’re using aren’t working, we might be able to provide more help.

my aim is to create a shortcode, this shortcode contains the template custom post type that I create (show list of custom post types in my way …) then i will embed this shortcode on the page using genterburg. Can you help me work the shortcode that I created that.

I would read up on how Blade templates are rendered: You’ll need to pass the data your template requires to it directly when you call \App\template()–that function works the same as the Laravel view() function you see demonstrated in those docs. Without data being passed to the template directly it won’t be able to output anything since you’re calling it in a context where the queries it normally depends on don’t exist. Since \App\template() returns a fully-rendered string, you shouldn’t need to use ob_start/clean().

I try the die function in archive-faqs.blade.php file it still shows ‘123123’, but if it turns off die, when it runs have_posts () it will die. (lines 19,20,21)

As you said pass the data to \ App \ template, so what it is specifically. Can you help me.
I tried passing the data as shown in the image, but it still doesn’t work.

function \App\template()returns a string.

You should echo the return value to render it to ob_get_clean()

This topic was automatically closed after 42 days. New replies are no longer allowed.