2

Struggling to debug this one.

The full log is as follows:

Next exception 'Twig_Error_Runtime' with message 'An exception has been thrown during the rendering of a template ("") in "book/poll-availability" at line 4.' in /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php:355
Stack trace:
#0 /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php(314): Twig_Template->displayWithErrorHandling(Array, Array)
#1 /var/www/craft/app/vendor/twig/twig/lib/Twig/Template.php(325): Twig_Template->display(Array)
#2 /var/www/craft/app/vendor/twig/twig/lib/Twig/Environment.php(293): Twig_Template->render(Array)
#3 /var/www/craft/app/services/TemplatesService.php(223): Twig_Environment->render('book/poll-avail...', Array)
#4 /var/www/craft/app/controllers/BaseController.php(74): Craft\TemplatesService->render('book/poll-avail...', Array)
#5 /var/www/craft/app/controllers/TemplatesController.php(55): Craft\BaseController->renderTemplate('book/poll-avail...', Array)
#6 [internal function]: Craft\TemplatesController->actionRender('book/poll-avail...', Array)
#7 /var/www/craft/app/framework/web/actions/CAction.php(109): ReflectionMethod->invokeArgs(Object(Craft\TemplatesController), Array)
#8 /var/www/craft/app/framework/web/actions/CInlineAction.php(47): CAction->runWithParamsInternal(Object(Craft\TemplatesController), Object(ReflectionMethod), Array)
#9 /var/www/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(Array)
#10 /var/www/craft/app/framework/web/CController.php(286): CController->runAction(Object(CInlineAction))
#11 /var/www/craft/app/framework/web/CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
#12 /var/www/craft/app/framework/web/CWebApplication.php(282): CController->run('render')
#13 /var/www/craft/app/framework/web/CWebApplication.php(141): CWebApplication->runController('templates/rende...')
#14 /var/www/craft/app/etc/web/WebApp.php(279): CWebApplication->processRequest()
#15 /var/www/craft/app/framework/base/CApplication.php(184): Craft\WebApp->processRequest()
#16 /var/www/craft/app/index.php(62): CApplication->run()
#17 /var/www/public-imperialhotels/en/index.php(22): require_once('/var/www/craft/...')
#18 {main}
REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&iframe=true&room-urns=

And the template in question looks like this:

{% set token = craft.request.getParam('search') %}

{% if (not craft.request.isAjax and not token ) %}
    {% exit 404 %}
{% endif %}

{% hook 'microsGetAvailabilityResults' %}

{% header 'Content-Type: application/json' %}

{% set data = {
    'complete': results.complete,
    'urn': results.urn,
    'pollUrl': craft.request.url ~ '?' ~ craft.request.queryStringWithoutPath
} %}

{{ data | json_encode | raw }}

So line 4 specifically is this:

    {% exit 404 %}

That should only be called if token is blank and as you can see from the REQUEST_URI, it should be set:

REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&iframe=true&room-urns=

Any suggestions?

What's most frustrating is that this has been picked up in server log monitoring on a live box and we can't replicate it.

The template exits correctly if we hit the URL with a non-Ajax request and if no token is defined, so what gives?

1
  • I tracked this down further to happen only when the page is run through Google Translate. Still not clear on why the error reporting shows no reason for the error though. – Russ Back Sep 25 '15 at 14:57
2

You're searching in the URI for a param with a key called search:

{% set token = craft.request.getParam('search') %}

But the in the URI it's called token:

REQUEST_URI=/en/book/poll-availability?token=9923444c-13b4-41bb-b7ab-9e339277bacc&iframe=true&room-urns=

Therefore when it's not an AJAX request this passes:

{% if (not craft.request.isAjax and not token ) %}

And a 404 is thrown:

{% exit 404 %}    
2
  • Good spot and that's what I'd expect. But it's not a 404 that gets thrown, it's the exception shown in my question above. – Russ Back Sep 28 '15 at 6:00
  • I'm seeing the same thing. {% exit 404 %} throws a runtime error in the logs, although everything looks fine on the front-end. – Eli Van Zoeren Dec 2 '15 at 20:56
2

Potentially just figured out why you were getting the error An exception has been thrown during the rendering of a template ("") which was happening to me.

I was doing a check where I wanted the result to a 404 page within a layout {% extends "_layout" %}, BUT, the 404 page itself was using the layout template, so was essentially causing a loop.

1
  • This was exactly my issue and couldn't figure out what I was doing wrong. The default 404 template does this so, if you throw an error in your main template, you will get this error. – Eric Chantigny Jan 30 '17 at 14:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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