My custom module: - Plugin/Ziektes.php array returns to hook_theme
public function build() {
$letter_path = 'B';
$path = base_path();
$current_url = Url::fromRoute('<current>');
$current_path = $current_url->toString();
// Query for newest articles and return max 3 results.
$query = \Drupal::entityQuery('node');
$news = $query->condition('type', 'ziekte')
->condition('status', 1)
->condition('title', $letter_path, 'STARTS_WITH' )
->sort('created', 'ASC')
->execute();
// LoadMultiple News in $nodes variable
$nodes = Node::loadMultiple($news);
// Return $nodes variable with name items to the module.
return array(
'#theme' => 'mytheme_ziektes',
'#items' => $nodes,
'#path' => $path,
'#url' => $current_path,
);
I have an alphabetical pagination printedn in twig like this:
Below this pagination there are the results of nodes for example in the letter 'B' there are nodes from content-type 'ziektes' that starts with the letter B.
As you can see in my module Ziektes.php file its not dynamic it uses
$letter_path = 'B';
->condition('title', $letter_path, 'STARTS_WITH' )
.
When there is clicked on a letter it goes to ziektes/'theletter' for example ziektes/b so that I can get the letter from the url and make the query dynamic.
But at page ziekte/*anyletter I get an 404 page not found so I've made a Controller and a routing:
Routing:
myroutingname.settings:
path: '/ziektes/{letter}'
defaults:
_controller: '\Drupal\myblocksroute\Controller\ZiektesController::ziekte'
_title: 'Routing Ziektes'
requirements:
_permission: 'access my routing ziektes'
Controller:
namespace Drupal\myblocksroute\Controller;
class ZiektesController
{
public function ziekte($letter) {
return [
'#title' => $letter
];
}
}
This returns the letter that is clicked, that's good! But Its only a new page with the as title the letter 'b' for example, I can't keep the twig template and the EntityQuery are not reachable from here. It suppose to stay at /ziektes form template but the url is /ziektes/b, so that the query will check the letter after the ziektes/ where I can make my $letter_path dynamic.
How can I do this?
#theme
function set. The reason you only see$letter
output is because thats all you're passing to the rendering layer.