Published pages result in 500 error

Suddenly, if I try to create a new page using the default Casper page.hbs template the admin console, I get a 500 error. Sorry I am pretty new at this, would appreciate any help.

This the log output:

[2020-04-08 06:31:11] ERROR “GET /resume/” 500 23ms

NAME: InternalServerError
MESSAGE: Cannot read property ‘match’ of undefined

level: normal

InternalServerError: Cannot read property ‘match’ of undefined
at new GhostError (/var/www/ghost/versions/3.11.0/core/server/lib/common/errors.js:10:26)
at _private.prepareError (/var/www/ghost/versions/3.11.0/core/server/web/shared/middlewares/error-handler.js:52:19)
at Layer.handle_error (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/layer.js:71:5)
at trim_prefix (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:315:13)
at /var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:335:12)
at next (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:275:10)
at Layer.handle_error (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/layer.js:67:12)
at trim_prefix (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:315:13)
at /var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:335:12)
at next (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:275:10)
at Layer.handle_error (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/layer.js:67:12)
at trim_prefix (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:315:13)
at /var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:335:12)
at Immediate.next (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:275:10)
at Immediate._onImmediate (/var/www/ghost/versions/3.11.0/node_modules/express/lib/router/index.js:635:15)
at runCallback (timers.js:706:11)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
at process.topLevelDomainCallback (domain.js:126:23)

TypeError: Cannot read property ‘match’ of undefined
at ExpressHbs.declaredLayoutFile (/var/www/ghost/versions/3.11.0/node_modules/express-hbs/lib/hbs.js:75:21)
at parseLayout (/var/www/ghost/versions/3.11.0/node_modules/express-hbs/lib/hbs.js:467:27)
at /var/www/ghost/versions/3.11.0/node_modules/express-hbs/lib/hbs.js:577:7
at getSourceTemplate (/var/www/ghost/versions/3.11.0/node_modules/express-hbs/lib/hbs.js:551:16)
at compileFile (/var/www/ghost/versions/3.11.0/node_modules/express-hbs/lib/hbs.js:573:5)
at /var/www/ghost/versions/3.11.0/node_modules/express-hbs/lib/hbs.js:660:12
at ExpressHbs.loadDefaultLayout (/var/www/ghost/versions/3.11.0/node_modules/express-hbs/lib/hbs.js:296:44)
at ExpressHbs.___express (/var/www/ghost/versions/3.11.0/node_modules/express-hbs/lib/hbs.js:648:8)
at View.render (/var/www/ghost/versions/3.11.0/node_modules/express/lib/view.js:135:8)
at tryRender (/var/www/ghost/versions/3.11.0/node_modules/express/lib/application.js:640:10)
at Function.render (/var/www/ghost/versions/3.11.0/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/var/www/ghost/versions/3.11.0/node_modules/express/lib/response.js:1012:7)
at renderer (/var/www/ghost/versions/3.11.0/core/frontend/services/routing/helpers/renderer.js:29:9)
at renderEntry (/var/www/ghost/versions/3.11.0/core/frontend/services/routing/helpers/render-entry.js:16:16)
at then (/var/www/ghost/versions/3.11.0/core/frontend/services/routing/controllers/entry.js:94:20)
at tryCatcher (/var/www/ghost/versions/3.11.0/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/var/www/ghost/versions/3.11.0/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/var/www/ghost/versions/3.11.0/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/var/www/ghost/versions/3.11.0/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/var/www/ghost/versions/3.11.0/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/var/www/ghost/versions/3.11.0/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/var/www/ghost/versions/3.11.0/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/var/www/ghost/versions/3.11.0/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues (/var/www/ghost/versions/3.11.0/node_modules/bluebird/js/release/async.js:15:14)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
at process.topLevelDomainCallback (domain.js:126:23)

This is happening with the default casper theme, or have you made changes?

Do you have a custom routes.yaml file?

I slightly modified the default Casper theme, but have not modified the routes.yaml file.

After doing some digging, I determined it was because I was trying to create a new page template by extending page.hbs through {{!< page}} (on the new template) and {{{block}}} (on the page.hbs template). If I do not use that method and just create a new hbs file in the theme root, I do not get the 500 error. Any ideas on why that is the case?

This is because the {{!< layout}} syntax is not a generic “extend” syntax, but rather defines a layout file to use.

You cannot use the same handlebars file as both a layout file and a template file.

default.hbs is the main layout file
page.hbs is the page template file

You can have secondary layout files, with shared layout logic e.g.

default.hbs - the base layout
default-page.hbs - middle layout e.g. does {{!< default}}
page.hbs - template file, does {{!< default-page}}
other-page.hbs - template file, does {{!< default-page}}

But using the same file as both a template and a layout will throw this error.

Thanks so much for the help. Just so I understand this correctly, I would need to create a default-page.hbs middle layout to avoid using page.hbs as both a layout and a template?

Yes exactly