Created
April 12, 2018 01:59
-
-
Save Greg-Boggs/9282df4347a522e5a19b77730c4f9012 to your computer and use it in GitHub Desktop.
Get the title of any page in Drupal 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $title = $this->titleResolver->getTitle($route_request, $route_match->getRouteObject()); | |
| // Many paths return a translatable markup object. | |
| if ($title instanceof TranslatableMarkup) { | |
| // Sets the title to the translated string. | |
| $title = $title->render(); | |
| } | |
| // Other paths, such as admin/structure/menu/manage/main, will | |
| // return a render array suitable to render using core's XSS filter. | |
| elseif (is_array($title) && array_key_exists('#markup', $title) && array_key_exists('#allowed_tags', $title)) { | |
| // Sets the title to the XSS filtered string. | |
| $title = Xss::filter($title['#markup'], $title['#allowed_tags']); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment