Childs missing template

I’ve been creating a site that has a structure like this:

  • home
  • news landing page
    • news item
  • category landing page
    • categories item

This is important: the category page and categories item are not taxonomy pages, but a listing page and regular childs.

So I basically want to have a structure like the blog skeleton: a page that lists its children, which are blog posts. My problem is creating the listing page is working correctly, but when I go into the child, I get a Template is not defined and i don’t know why.

This is what I’m doing

I have created to yaml blueprints:

  • category-page.yaml
  • categories.yaml

The category page has a child_type: categories and I declared the default child type as categories:

title: Category Landing Page
'@extends':
    type: default
    context: blueprints://pages

child_type: categories

title: Default

rules:
  slug:
    pattern: "[a-z][a-z0-9_\-]+"
    min: 2
    max: 80

form:
  fields:
    tabs:
      type: tabs
      active: 1

      fields:
        advanced:
          fields:
            overrides:
              fields:
                header.child_type:
                  default: categories
        blog:
          type: tab
          title: Lista de categorías

          fields:
            header.content.items:
              type: textarea
              yaml: true
              label: Items
              default: '@self.children'

            header.content.limit:
              type: text
              label: Max Item Count
              default: 5
              validate:
                required: true
                type: int
                min: 1

            header.content.order.by:
              type: select
              label: Order By
              default: date
              options:
                folder: Folder
                title: Title
                date: Date
                default: Default

            header.content.order.dir:
              type: select
              label: Order
              default: desc
              options:
                asc: Ascending
                desc: Descending

            header.content.pagination:
              type: toggle
              label: Pagination
              highlight: 1
              default: 1
              options:
                1: PLUGIN_ADMIN.ENABLED
                0: PLUGIN_ADMIN.DISABLED
              validate:
                type: bool


            header.content.url_taxonomy_filters:
              type: toggle
              label: URL Taxonomy Filters
              highlight: 1
              default: 1
              options:
                1: PLUGIN_ADMIN.ENABLED
                0: PLUGIN_ADMIN.DISABLED
              validate:
                type: bool

This works ok.

Now, my categories.yaml (long one with a bunch of fields) has this:

title: Category

rules:
  slug:
    pattern: '[a-zA-Zа-яA-Я0-9_\-]+'
    min: 1
    max: 200

form:
  validation: loose

  fields:

    tabs:
      type: tabs
      active: 1

      fields:
        content:
          type: tab
          title: PLUGIN_ADMIN.CONTENT

          fields:
            header.title:
              type: text
              autofocus: true
              style: vertical
              label: Nombre de categoría

            content:
                type: markdown
                validate:
                  type: textarea

            uploads:
              type: pagemedia
              label: Logo
              multiple: false
              destination: '@self'
              accept:
                image/*

            header.requisitos:
              type: editor
              label: Requisitos
              default: Ingrese los requisitos de esta categoría
              validate:
                required: false
            steps:
              type: section
              title: Pasos a seguir
              underline: true
            steps_instructions:
              type: display
              size: large
              label: Instrucciones
              markdown: true
              content: "Si no desea utilizar uno de los siguientes pasos, deje los campos vacíos"

            steps_signup:
              type: section
              title: 1. Inscripción
              underline: false
            steps_signup_title:
              label: Título
              type: text
              placeholder: Inscripción
            steps_signup_description:
              label: Descripción (2 renglones)
              type: textarea
            steps_signup_date_start:
              label: Fecha inicial
              type: text
              placeholder: ej. 15 de enero
            steps_signup_date_end:
              label: Fecha cierre
              type: text
              placeholder: ej. 20 de marzo
            steps_signup_file:
              type: file
              label: Documento adjunto de este paso
              help: Solamente PDF, word o excel
              multiple: false
              destination: '@self'
              accept:
                - application/pdf
                - application/msword
                - application/vnd.openxmlformats-officedocument.wordprocessingml.document
                - application/vnd.ms-excel
                - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

            steps_diagnose:
              type: section
              title: 2. Diagnóstico inicial
              underline: false
            steps_diagnose_title:
              label: Título
              type: text
              placeholder: Diagnóstico inicial
            steps_diagnose_description:
              label: Descripción (2 renglones)
              type: textarea
            steps_diagnose_date_start:
              label: Fecha inicial
              type: text
              placeholder: ej. 15 de enero
            steps_diagnose_date_end:
              label: Fecha cierre
              type: text
              placeholder: ej. 20 de marzo
            steps_diagnose_file:
              type: file
              label: Documento adjunto de este paso
              help: Solamente PDF, word o excel
              multiple: false
              destination: '@self'
              accept:
                - application/pdf
                - application/msword
                - application/vnd.openxmlformats-officedocument.wordprocessingml.document
                - application/vnd.ms-excel
                - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

            steps_plan:
              type: section
              title: 3. Plan de trabajo
              underline: false
            steps_plan_title:
              label: Título
              type: text
              placeholder: Plan de trabajo
            steps_plan_description:
              label: Descripción (2 renglones)
              type: textarea
            steps_plan_date_start:
              label: Fecha inicial
              type: text
              placeholder: ej. 15 de enero
            steps_plan_date_end:
              label: Fecha cierre
              type: text
              placeholder: ej. 20 de marzo
            steps_plan_file:
              type: file
              label: Documento adjunto de este paso
              help: Solamente PDF, word o excel
              multiple: false
              destination: '@self'
              accept:
                - application/pdf
                - application/msword
                - application/vnd.openxmlformats-officedocument.wordprocessingml.document
                - application/vnd.ms-excel
                - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

            steps_report:
              type: section
              title: 4. Informe final
              underline: false
            steps_report_title:
              label: Título
              type: text
              placeholder: Informe final
            steps_report_description:
              label: Descripción (2 renglones)
              type: textarea
            steps_report_date_start:
              label: Fecha inicial
              type: text
              placeholder: ej. 15 de enero
            steps_report_date_end:
              label: Fecha cierre
              type: text
              placeholder: ej. 20 de marzo
            steps_report_file:
              type: file
              label: Documento adjunto de este paso
              help: Solamente PDF, word o excel
              multiple: false
              destination: '@self'
              accept:
                - application/pdf
                - application/msword
                - application/vnd.openxmlformats-officedocument.wordprocessingml.document
                - application/vnd.ms-excel
                - application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

        coordinator:
          type: tab
          title: Coordinador
          fields:

            coordinator_section:
              type: section
              title: Coordinador
              underline: true
            coordinator_picture:
              type: file
              label: Foto
              multiple: false
              destination: 'self@'
              random_name: false
              avoid_overwriting: true
              accept:
                - image/*
            coordinator_name:
              label: Nombre
              type: text
            coordinator_name:
              label: Organización
              type: text
            coordinator_email:
              label: Email
              type: text
            coordinator_tel:
              label: Teléfono
              type: text

        documents:
          type: tab
          title: Documentos
          fields:
            documents_section:
              type: section
              title: Documentos importantes
              underline: true
            documents_instructions:
                type: display
                size: large
                label: Instrucciones
                markdown: true
                content: "Ingrese documentos importantes para esta categoría"
            document_files:
              name: documentos
              type: list
              label: Documentos
              fields:
                .document_title:
                  type: text
                  label: Nombre del documento
                .document_description:
                  type: textarea
                  label: Descripción
                .document_select:
                  type: select
                  label: Tipo de documento
                  size: small
                  options:
                    download: Descargable
                    website: Sitio web
                    video: Video
                .document_url:
                  type: url
                  label: URL externa
                .document_file_upload:
                  type: file
                  label: Suba un adjunto
                  help: Solamente PDF, word o excel
                  multiple: false
                  destination: '@self'
                  accept:
                    - image/*

        resources:
          type: tab
          title: Recursos
          fields:
            documents_section:
              type: section
              title: Recursos
              underline: true
            resource_instructions:
                type: display
                size: large
                label: Instrucciones
                markdown: true
                content: "Ingrese recursos importantes para esta categoría"
            document_files:
              name: documentos
              type: list
              label: Documentos
              fields:
                .resource_title:
                  type: text
                  label: Nombre del recurso
                .resource_description:
                  type: textarea
                  label: Descripción
                .recource_select:
                  type: select
                  label: Tipo de recurso
                  size: small
                  options:
                    download: Descargable
                    website: Sitio web
                    video: Video
                .recource_url:
                  type: url
                  label: URL externa
                .resource_file_upload:
                  type: file
                  label: Suba un adjunto
                  help: Solamente PDF, word o excel
                  multiple: false
                  destination: '@self'
                  accept:
                    - image/*

        options:
          type: tab
          title: PLUGIN_ADMIN.OPTIONS

          fields:

            publishing:
              type: section
              title: PLUGIN_ADMIN.PUBLISHING
              underline: true

              fields:
                header.published:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.PUBLISHED
                  help: PLUGIN_ADMIN.PUBLISHED_HELP
                  highlight: 1
                  size: medium
                  options:
                    1: PLUGIN_ADMIN.YES
                    0: PLUGIN_ADMIN.NO
                  validate:
                    type: bool

                header.date:
                  type: datetime
                  label: PLUGIN_ADMIN.DATE
                  toggleable: true
                  help: PLUGIN_ADMIN.DATE_HELP

                header.publish_date:
                  type: datetime
                  label: PLUGIN_ADMIN.PUBLISHED_DATE
                  toggleable: true
                  help: PLUGIN_ADMIN.PUBLISHED_DATE_HELP

                header.unpublish_date:
                  type: datetime
                  label: PLUGIN_ADMIN.UNPUBLISHED_DATE
                  toggleable: true
                  help: PLUGIN_ADMIN.UNPUBLISHED_DATE_HELP

                header.metadata:
                  toggleable: true
                  type: array
                  label: PLUGIN_ADMIN.METADATA
                  help: PLUGIN_ADMIN.METADATA_HELP
                  placeholder_key: PLUGIN_ADMIN.METADATA_KEY
                  placeholder_value: PLUGIN_ADMIN.METADATA_VALUE

            taxonomies:
              type: section
              title: PLUGIN_ADMIN.TAXONOMIES
              underline: true

              fields:
                header.taxonomy:
                  type: taxonomy
                  label: PLUGIN_ADMIN.TAXONOMY
                  multiple: true
                  validate:
                    type: array

        advanced:
          type: tab
          title: PLUGIN_ADMIN.ADVANCED

          fields:
            columns:
              type: columns
              fields:
                column1:
                  type: column
                  fields:

                    settings:
                      type: section
                      title: PLUGIN_ADMIN.SETTINGS
                      underline: true

                    folder:
                      type: text
                      label: PLUGIN_ADMIN.FOLDER_NAME
                      validate:
                        rule: slug

                    route:
                      type: parents
                      label: PLUGIN_ADMIN.PARENT
                      classes: fancy

                    name:
                      type: select
                      classes: fancy
                      label: PLUGIN_ADMIN.PAGE_FILE
                      help: PLUGIN_ADMIN.PAGE_FILE_HELP
                      default: default
                      data-options@: '\Grav\Common\Page\Pages::pageTypes'

                    header.body_classes:
                      type: text
                      label: PLUGIN_ADMIN.BODY_CLASSES


                column2:
                  type: column

                  fields:
                    order_title:
                      type: section
                      title: PLUGIN_ADMIN.ORDERING
                      underline: true

                    ordering:
                      type: toggle
                      label: PLUGIN_ADMIN.FOLDER_NUMERIC_PREFIX
                      help: PLUGIN_ADMIN.FOLDER_NUMERIC_PREFIX_HELP
                      highlight: 1
                      options:
                        1: PLUGIN_ADMIN.ENABLED
                        0: PLUGIN_ADMIN.DISABLED
                      validate:
                        type: bool

                    order:
                      type: order
                      label: PLUGIN_ADMIN.SORTABLE_PAGES
                      sitemap:

            overrides:
              type: section
              title: PLUGIN_ADMIN.OVERRIDES
              underline: true

              fields:

                header.dateformat:
                  toggleable: true
                  type: select
                  size: medium
                  selectize:
                    create: true
                  label: PLUGIN_ADMIN.DEFAULT_DATE_FORMAT
                  help: PLUGIN_ADMIN.DEFAULT_DATE_FORMAT_HELP
                  placeholder: PLUGIN_ADMIN.DEFAULT_DATE_FORMAT_PLACEHOLDER
                  data-options@: '\Grav\Common\Utils::dateFormats'
                  validate:
                    type: string

                header.menu:
                  type: text
                  label: PLUGIN_ADMIN.MENU
                  toggleable: true
                  help: PLUGIN_ADMIN.MENU_HELP

                header.slug:
                  type: text
                  label: PLUGIN_ADMIN.SLUG
                  toggleable: true
                  help: PLUGIN_ADMIN.SLUG_HELP
                  validate:
                    message: PLUGIN_ADMIN.SLUG_VALIDATE_MESSAGE
                    rule: slug

                header.redirect:
                  type: text
                  label: PLUGIN_ADMIN.REDIRECT
                  toggleable: true
                  help: PLUGIN_ADMIN.REDIRECT_HELP

                header.process:
                  type: checkboxes
                  label: PLUGIN_ADMIN.PROCESS
                  toggleable: true
                  config-default@: system.pages.process
                  default:
                    markdown: true
                    twig: false
                  options:
                    markdown: Markdown
                    twig: Twig
                  use: keys

                header.twig_first:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.TWIG_FIRST
                  help: PLUGIN_ADMIN.TWIG_FIRST_HELP
                  highlight: 0
                  options:
                    1: PLUGIN_ADMIN.YES
                    0: PLUGIN_ADMIN.NO
                  validate:
                    type: bool

                header.never_cache_twig:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.NEVER_CACHE_TWIG
                  help: PLUGIN_ADMIN.NEVER_CACHE_TWIG_HELP
                  highlight: 0
                  options:
                    1: PLUGIN_ADMIN.YES
                    0: PLUGIN_ADMIN.NO
                  validate:
                    type: bool

                header.child_type:
                  type: select
                  toggleable: true
                  label: PLUGIN_ADMIN.DEFAULT_CHILD_TYPE
                  default: default
                  placeholder: PLUGIN_ADMIN.USE_GLOBAL
                  data-options@: '\Grav\Common\Page\Pages::types'

                header.routable:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.ROUTABLE
                  help: PLUGIN_ADMIN.ROUTABLE_HELP
                  highlight: 1
                  options:
                    1: PLUGIN_ADMIN.ENABLED
                    0: PLUGIN_ADMIN.DISABLED
                  validate:
                    type: bool

                header.cache_enable:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.CACHING
                  highlight: 1
                  options:
                    1: PLUGIN_ADMIN.ENABLED
                    0: PLUGIN_ADMIN.DISABLED
                  validate:
                    type: bool

                header.visible:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.VISIBLE
                  help: PLUGIN_ADMIN.VISIBLE_HELP
                  highlight: 1
                  options:
                    1: PLUGIN_ADMIN.ENABLED
                    0: PLUGIN_ADMIN.DISABLED
                  validate:
                    type: bool

                header.debugger:
                  type: toggle
                  toggleable: true
                  label: PLUGIN_ADMIN.DEBUGGER
                  help: PLUGIN_ADMIN.DEBUGGER_HELP
                  highlight: 1
                  options:
                    1: PLUGIN_ADMIN.ENABLED
                    0: PLUGIN_ADMIN.DISABLED
                  validate:
                    type: bool

                header.template:
                  type: text
                  toggleable: true
                  label: PLUGIN_ADMIN.DISPLAY_TEMPLATE

                header.append_url_extension:
                  type: text
                  label: PLUGIN_ADMIN.APPEND_URL_EXT
                  toggleable: true
                  help: PLUGIN_ADMIN.APPEND_URL_EXT_HELP

            admin_only:
              type: section
              title: PLUGIN_ADMIN.ADMIN_SPECIFIC_OVERRIDES
              underline: true

              fields:

                header.admin.children_display_order:
                  type: select
                  label: PLUGIN_ADMIN.ADMIN_CHILDREN_DISPLAY_ORDER
                  help: PLUGIN_ADMIN.ADMIN_CHILDREN_DISPLAY_ORDER_HELP
                  toggleable: true
                  classes: fancy
                  default: 'collection'
                  options:
                    'default': 'Ordered by Folder name (default)'
                    'collection': 'Ordered by Collection definition'


                header.order_by:
                  type: hidden

                header.order_manual:
                  type: hidden
                  validate:
                    type: commalist

                blueprint:
                  type: blueprint

I have 2 templates that are important here, inside my theme:

  1. mytheme/templates:
    category-page.html.twig
    Code below:
    {% embed ‘partials/base.html.twig’ %}

     	{% set collection = page.collection() %}
    
     	{% block content %}
    
     		<div class="blog-header">
     			<h1>{{ page.header.title }}</h1>
     			{{ page.content }}
     		</div>
    
     			{% if config.plugins.breadcrumbs.enabled %}
     				{% include 'partials/breadcrumbs.html.twig' %}
     			{% endif %}
    
     		<div class="content-wrapper blog-content-list grid pure-g">
     			<div id="listing" class="block pure-u-2-3 h-feed">
     				{% for child in collection %}
     			        {% include 'partials/categories_item.html.twig' with {'category':page, 'page':child, 'truncate':true} %}
     			  {% endfor %}
    
             {% if config.plugins.pagination.enabled and collection.params.pagination %}
                 {% include 'partials/pagination.html.twig' with {'base_url':page.url, 'pagination':collection.params.pagination} %}
             {% endif %}
     			</div>
     		</div>
     	{% endblock %}
    
     {% endembed %}
    
  2. mytheme/templates/partials:
    categories_item.html.twig
    Code below:
    (I know it still has blog references from the antimatter theme but I believe they should not interfiere with the call to the tamplate)

        {% set header_image = page.header.header_image|defined(true) %}
        {% set header_image_width  = page.header.header_image_width|defined(900) %}
        {% set header_image_height = page.header.header_image_height|defined(300) %}
        {% set header_image_file = page.header.header_image_file %}

        <div class="list-blog-header">
            {% if page.header.link %}
                <h4 class="p-name">
                    {% if page.header.continue_link is not sameas(false) %}
                    <a href="{{ page.url }}"><i class="fa fa-angle-double-right u-url"></i></a>
                    {% endif %}
                    <a href="{{ page.header.link }}" class="u-url">{{ page.title }}</a>
                </h4>
            {% else %}
                <h4 class="p-name"><a href="{{ page.url }}" class="u-url">{{ page.title }}</a></h4>
            {% endif %}

            {% if page.taxonomy.tag %}
            <span class="tags">
                {% for tag in page.taxonomy.tag %}
                <a href="{{ blog.url|rtrim('/') }}/tag{{ config.system.param_sep }}{{ tag }}" class="p-category">{{ tag }}</a>
                {% endfor %}
            </span>
            {% endif %}
            
            <div class="blog-main-image">
              {% if truncate %}
                  {% set header_image_media = page.media.images|first %}
                  {{ header_image_media.cropZoom(200, 150).html }}
              {% else %}
                  {% set header_image_media = page.media.images|first %}
                  {{ header_image_media.resize(700).html }}
              {% endif %}
            </div>
            
        </div>

        <div class="list-blog-padding">

        {% if page.header.continue_link is sameas(false) %}
            <div class="e-content">        
                {{ page.content }}
            </div>
            {% if not truncate %}
            {% set show_prev_next = true %}
            {% endif %}
        {% elseif truncate and page.summary != page.content %}
            <div class="p-summary e-content">
                {{ page.summary }}
                <p><a href="{{ page.url }}">{{ 'BLOG.ITEM.CONTINUE_READING'|t }}</a></p>
            </div>
        {% elseif truncate %}
            <div class="p-summary e-content">
                {{ page.content }}
                <p><a href="{{ page.url }}">{{ 'BLOG.ITEM.CONTINUE_READING'|t }}</a></p>
            </div>
        {% else %}
            <div class="e-content">
                {{ page.content }}
            </div>

            {% if config.plugins.comments.enabled %}
                {% include 'partials/comments.html.twig' %}
            {% endif %}

            {% set show_prev_next = true %}
        {% endif %}

        {% if show_prev_next %}

            <p class="prev-next">
                {% if not page.isFirst %}
                    <a class="button" href="{{ page.nextSibling.url }}"><i class="fa fa-chevron-left"></i> {{ 'BLOG.ITEM.NEXT_POST'|t }}</a>
                {% endif %}

                {% if not page.isLast %}
                    <a class="button" href="{{ page.prevSibling.url }}">{{ 'BLOG.ITEM.PREV_POST'|t }} <i class="fa fa-chevron-right"></i></a>
                {% endif %}
            </p>
        {% endif %}

        </div>
    </div>

Whenever I click a categories item, I get this:
RuntimeException (400)
Template “categories.html.twig” is not defined.

Why is grav looking for the “categories.html.twig” in the templates root instead of “categories_item.html.twig” the partials folder? Is the “_item.html.twig” not a default pattern in grav for children of a collection?

Any light you might shed can help me! I’m new to grav and I have looked through the documentation deeply but have gotten no hints from the collections or listings documentation.

I found what I did wrong: I missinterpreted the whole template structure thing. I need to add a categories.html.twig in order to call the partial categories_item.html.twig.

Actually, the latter is optional :stuck_out_tongue: you could do everything in the categories.html.twig template.