-
Notifications
You must be signed in to change notification settings - Fork 44
Naming with underscores #49
Comments
I will see what we can do here and let you know. |
Bump on this. Ran into the same issue. |
Aaaaand the same here. |
Just a note that I am looking into this. |
Same problem here, I'm using the Single.php controller for now. Thanks for looking into it! |
How about something like this? Add $template property to Sober\Controller\Controller <?php
namespace Sober\Controller;
class Controller
{
protected $active = true;
protected $tree = false;
protected $data = [];
// Default is null (not set)
protected $template = false;
...
public function getTemplate() {
return $this->template;
}
} controller.php loader() function function loader()
{
$loader = new Loader();
foreach ($loader->getData() as $template => $class) {
$instance = new $class; // instantiate class...
if ($instance->getTemplate()) { // ...so we can access its methods
$template = $instance->getTemplate();
}
// Pass data filter
add_filter('sage/template/' . $template . '-data/data', function ($data) use ($loader, $class) {
$controller = new $class();
$controller->__setup();
return array_merge($loader->getAppData(), $loader->getPostData(), $controller->__setTreeData($data), $controller->__getData());
});
// Class alais
class_alias($class, (new \ReflectionClass($class))->getShortName());
}
} Now you can over-ride the template name inside of your controllers. class SingleResourceCollection
{
protected $template = 'partials/content-single-resource_collection';
} |
That looks great! Nice solution! |
Earlier versions of Controller had the option to specify the template. I think that is the best solution for underscores. I'll add this to dev-master. Thanks @webstractions |
@darrenjacoby You're welcome. |
@webstractions's solution works great! Had to make one tweak to get it there, though: $instance = new $class; // instantiate class...
if ($instance->getTemplate()) { // ...so we can access its methods
$template = $instance->getTemplate();
} Without that, I got errors about trying to call a method on a string. Works like a charm now, though! Thanks! |
@alwaysblank Looks good! Updated loader() code above to match. |
I'll be adding this to dev-master soon. |
Sorry if this issue already exists. The only similar one I was able to find was #20.
Problem
Controller loading doesn't occur with custom post types using underscores.
Example:
resource_collection
Details
I have a custom post type of
resource_collection
. It's relevant files include:resources/views/partials/content-single-resource_collection.blade.php
app/controllers/SingleResourceCollection.php
Hierarchy Debugger:
Thanks for any help/clarification!
The text was updated successfully, but these errors were encountered: