6

Here's one way to do it – not super elegant, but it works: {% set template %} {{- include('sometemplatethatdoesntexist', ignore_missing = true) -}} {% endset %} {% if not template %} {% exit 404 %} {% endif %} {{ template }}


5

By default a full stack trace will only be assembled and logged if an exception is thrown (which is what you're looking at in your 2nd example) mainly for performance reasons - cycling through the backtrace and assembling all of that info is a relatively expensive operation. Standard calls to MyPlugin::log or Craft::log will get a partial backtrace added to ...


4

There are several ways you could go about this. One that I tend to prefer is to go ahead and have your controller grab whatever data it needs from POST and populate a Model with it. That model is what gets passed into your service layer. Your service layer can run validation on the model (if any validation fails, you can retrieve the errors with $model-&...


4

Your guess is correct... as the docs say, you should never have devMode enabled in production environments specifically for reasons like this (as well as many others). If you find errors that are leaking sensitive server info with devMode disabled, then that is a bug and should be reported to support@buildwithcraft.com.


3

There are several things that might be the issue in such cases, I'll list a few of them Did you change your index.php so maybe Craft is unable to detect the current site? Are there different index.php files in different folders in order to do the multisite setup instead of the single one? -> You should only have one for all Do you have any plugins that ...


3

When submitting a payment form to the commerce/payments/pay controller action there are three potential sources of error messages. If you are submitting via a normal form submission (not ajax) you will be able to get access to the errors in the following manner from your template. General Errors {% set flashError = craft.app.session.getFlash('error') %} ...


3

For whatever reason, your site isn't able to find the image. And since your Twig code isn't being defensive, it's failing ungracefully. {% set image = block.media.first() %} This first part is fine... I'm assuming that media is an Assets relationship field. You're attempting to fetch the first asset, and set that to image. Here's the kicker... when no ...


2

It's a bit hard to tell from this snippet, but if image is an asset field it's important to remember that these are returned as arrays so you have to access the url more like block.image.first().url. However, if the image variable is set elsewhere this probably won't help. EDIT: Relevant docs


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.


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 ...


2

Yii does have onError and onException events that get raised when PHP errors/warnings/notices and exceptions happen. You'd need to write a plugin that listened to those and did the Bugsnag magic, then.


2

It depends on the type of errors that are being thrown. If they are Twig/template errors, then you can can set the suppressTemplateErrors config setting to true and they will simply get logged and the page request will continue as usual. If they are non-Twig exceptions, then you'd have to do something more fancy like make a plugin that's essentially a ...


2

You mean the errors of your form? You can access those via paymentForm {% for attribute, error in paymentForm %} {{ attribute }}: {{ dump(error) }} {% endfor %}


2

By setting the action: "#errortag" seems to stop the form submitting if there are no errors. So instead I have added the following code and this seems to work; {% if form.hasErrors %} {% includejs %} $(document).ready(function () { $('html, body').animate({ scrollTop: $('#formErrors').offset().top-110 }, 1000); }); {% endincludejs %} {% ...


1

Errors for the users/save-user action are recorded against the user object, not the session object. If the user is logged-out, the object is named user but if they are logged-in you must use currentUser. Generally speaking you can retrieve errors from Yii objects in several ways, but for field-by-field errors, I prefer the simplicity of getFirstError() (You ...


1

Thanks to a teammate, got this working! Needed to change the conditional wrapping my error messages from {% if entry is defined %} to {% if entry is defined and entry is not null %}


1

I was able to use the "flash message" that's included in their demo templates (shop/_layout/main) {% set flashNotice = craft.app.session.getFlash('notice') %} {% if flashNotice %} <div class="bg-blue text-white"> <div class="container mx-auto px-6 py-4"> {{ flashNotice }} </div> </div> {% endif %} ...


1

You can just add the action override: action: "#errortag" So your template code would look something like this: {{ craft.freeform.form("proefles", { instructionsBelowField: true, action: "#errortag" }).render() }}


1

So, it turns out (as is often the case) that posting the problem makes you look at it in a fresh light, and as such I found my own solution. What I needed to do (leaving this here in case someone else has a similar problem and come looking for help) was to make the following change to my rendering-controller: old public function ...


1

Any chance you're out of disk space? That error shows that it can't create a file in /tmp which means either the permissions on /tmp are wrong, or potentially you're out of disk space. c.f.: https://stackoverflow.com/questions/11997012/mysql-cant-create-write-to-file-tmp-sql-3c6-0-myi-errcode-2-what-does As for the error page, if you just want to view the ...


1

Thanks everyone for taking a look. I forgot that I had implemented something on the receiving templates that allowed you to navigate between articles from the newsletter, if the referral url was the newsletter. After I implemented the text only block, I forgot to change this to ignore those blocks.


1

Ahh this is a bit misleading because the docs don't really spell it out. "formHandle" according to the docs really feels like it might be the variable you set your form to, but it's literally the form handle you got when you titled your form in the CMS. So if your form starts with: {% set apple = craft.amForms.getForm('fireTruck') %} your error code needs ...


1

Not sure what validation error you're expecting from the template code. Both firstName and lastName are non-required fields that will basically accept any input. photoUrl could return a validation error if, for example, you tried to upload a .txt file to but you're not calling the errorList() macro on that field. Not sure if userDescription is required or ...


1

I don't believe there is any 'built in code' you could use. You have 2 options though. You could either do this in twig by checking all fields in a tab and adding an error class to the tab: {% set actionClasses = "" %} {% if (sale.getErrors('discountAmount') or sale.getErrors('discountType')) %} {% set actionClasses = "error" %} {% endif %} {% set ...


1

Just re-throw the exception and pretend like nothing ever happened... try { // Some code which might produce an error } catch (\Exception $e) { if (craft()->request->isCpRequest()) { // Do something with $e->getMessage() } else { // Nothing to see here... throw $e; } }


Only top voted, non community-wiki answers of a minimum length are eligible