just trying to understand how the classes work. If i add a HelloWorld.php then this class will run for the included /hello-world sample post
but data (public functions) are not passed to the template.
Is it possible to create a page/class for a specific single post?
for instance in Timber/Twig you can create eg single-103.twig where 103 is the post id, and this gets pulled into single.php , Timber::render( array( 'single-' . $post->ID . '.twig', 'single-' . $post->post_type . '.twig', 'single.twig' ), $context );)
which could be done easily with the Sage single.php
but in terms of the actual page /hello-world and the class HelloWorld, is there a way to inject that data (ie the controller functions) into a template?
I can see app/controllers/HelloWorld.php constructor gets called since hello-world is a body class, but none of the function variables are available. Only App.php and Single.php variables are showing with @debug
I had assumed all controllers would pass variables to the template via their functions, so I’ve misunderstood how it is wired up.
I’ve got a fundamental misunderstanding I think here
taking for instance the default /sample-page
I can create a page-sample-page.blade.php that loads ok for /sample-page but I thought if I added a app/Controllers/SamplePage.php then this would run (due to the sample-page body class) and then expose it’s variables
when I add @debug to page-sample-page.blade.php I get a bunch of notices Notice: Undefined variable: last in /srv/www/trellis.test/current/web/app/themes/sage/vendor/soberwp/controller/src/Blade.php on line *28* Notice: Trying to get property 'tree' of non-object in /srv/www/trellis.test/current/web/app/themes/sage/vendor/soberwp/controller/src/Blade.php on line 28
etc
and the only variable data is for App
@debug
App
Data
postobject
site_namestringline 9—12
Methods
titleline 14—32
what am I missing here please? which body classes will actually pass variables to the page?
again I’m using the default install here without any changes other than adding the app/Controllers/SamplePage.php file