Hello everybody,

I am new to Drupal and kind of a newbie.
I used the Blog Module https://www.drupal.org/project/blog to create my blog.
Now i wanted to add a custom field that i created to the Page Title on the Blog Post (Full View of Blog Post).
If i add the custom field in the Blog Page (all blog posts view) it works fine.

File (node--view--blog--blog--all.html.twig):

{%
  set classes = [
    'node',
    'node--type-' ~ node.bundle|clean_class,
    node.isPromoted() ? 'node--promoted',
    node.isSticky() ? 'node--sticky',
    not node.isPublished() ? 'node--unpublished',
    view_mode ? 'node--view-mode-' ~ view_mode|clean_class,
  ]
%}
{{ attach_library('classy/node') }}
<article{{ attributes.addClass(classes) }}>

  {% if display_submitted %}
    <footer class="node__meta">
      {{ author_picture }}
      <div{{ author_attributes.addClass('node__submitted') }}>
        {{ metadata }}
      </div>
    </footer>
  {% endif %}

  <div{{ content_attributes.addClass('node__content') }}>

    {{ content.field_blog_image }}

    <div class="date-blog">
      {% set createdDate = node.getCreatedTime|format_date('blog_date') %}
      {% trans %} {{ createdDate }} {% endtrans %}
    </div>

    {{ title_prefix }}
    {% if not page %}
      <h2{{ title_attributes }}>
        <a href="{{ url }}" rel="bookmark">{{ label }}
        {{ content.field_untertitel }}<!-- THIS IS MY CUSTOM FIELD THAT I ADDED AND ITS WORKING -->
       </a>
      </h2>
    {% endif %}
    {{ title_suffix }}

    {{ content.body }}
    
    {{ content.links }}
    
  </div>

</article>

When i add it like this in my page-title.html.twig File it doesnt work at all.

File (page-title.html.twig):

{{ title_prefix }}
{% if title %}
  <h1{{ title_attributes.addClass('page-title') }}>{{ title }}</h1>
{% endif %}
{{ title_suffix }}

<!-- This Part is added by me but doesnt work -->
{% if not page %}
	<span class="sub-title">
		{{ content.field_untertitel }}
	</span>
{% endif %}

What am i doing wrong here?
Thank you guys for helping <3

Comments

Jeff Burnz’s picture

The field is part of the node and by default it will only be available to the node and page templates. If you want to access fields from another template (such as the page title) you'll need to add them via preprocess.