how can I change page title drupal 8 in node with some options? I want change my title on "test" if node have field "field_section" is "dogs". Just in this page I want showing in "field--node--title.html.twig" 'test'.

I tried function test_theme_preprocess_field(&$variables, $hook) {
if($variables['field_name']=='title'){ $variables['items']['changetitle']=true; // kint($variables); } }

But I don't know how to search from preprocess field other paramters other fields like my field in node 'field_section'.

I want mix in preproccesing_field 'if field_section have value 'dogs' then showing page_title is 'test'.

2 Answers 2


You can fix all the things with RouteSubscriberBase https://www.drupal.org/docs/8/api/routing-system/altering-existing-routes-and-adding-new-routes-based-on-dynamic-ones...


/** @var Route $entityUserEditForm */
$entityUserEditFormRoute = $collection->get('entity.user.edit_form');

// Change default user details entity form and title.
if ($entityUserEditFormRoute) {
    '_entity_form' => 'user.complete_registration_form',
    '_title' => 'Complete Registration Form',

Is there any reason you don't want to do this in the node template? The following is pseudo code, but you could do something like this:

{% if content.field_section == 'dogs' %}
{% else %}
  {{ label }}
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.