I have a page called “Join us” and I am having problems to get the acf values through controllers.
If I add @debug in my template file I can’t see the variables output.
i have a page called “Join us” so I created the page-join-us.php inside /resources/views/
inside /resources/scripts/routes/ I created the join.js file and I updated the /resources/scripts/main.js (the js works well)
inside /app/controllers/ i created JoinUs.php with this code
namespace App\Controllers;
use Sober\Controller\Controller;
class JoinUs extends Controller
{
protected $acf = true; // this will add all the ACF fields to the $data variable for this page
public function job_test() {
return get_field('job_test'); // this is a test to
}
}
this is what I can see with the @debug in my “Join us” page, but as you can see there is not the JoinUs variable
The best way to debug would be to view the body classes for that page, does it match the Controller name? (bearing in mind Controller names are converted from camelCase to match the body class)
It actually depends on the WordPress hierarchy. Controller uses https://github.com/Brain-WP/Hierarchy which adds classes depending on the template hierarchy. The body classes passed in by default from WP (ie. the ones without -data), are technically not following the default WP template hierarchy we use when creating templates/views. I made this decision when building Controller to try mimic Controllers to templates/views as closely as possible to provide a predictable structure.
This question has come up a few times, so adding the Controller names which could be used in a template/view would be a nice touch to @debug. I’ll get it added in for the next release.