I'm creating custom error pages for the 404 and 500 error in my Symfony project. I would like to know how to internationalize those pages.
What I mena by thta is that I already know how to use {% trans %} in my twig and how to create the file whit the translated texte. What I
Usally, my urls look like that: kevinduguay.ca/en/..... but in the case of an error page, /en might not be there, but I still need to find in what language I should siplay the page. Maybe the language of the country?
Hope you can help me.
by following this cookbook, you can find current local in error page by:
$request->getLocal();
Although you dont nedd to this, trans() method detect current local
Related
I have my site running on a CentOS server, and list view is fine, but when I click on a link to go to a detail view, I now get a Server Error (500).There are no errors in the nginx logs, and I don't know where else to look to debug these. I have just upgraded to django 3, I'm suspecting there is something that I have not corrected for the upgrade, but I don't know what that would be as I am not getting any error messages or stack trace, just Server Error (500). What can I do to find the issue please?
You're probably aware of it, but have you activated Debug mode in the settings.py? So far I always got a very detailed error report on reload when I broke something. Did you change any of the models? I would make sure that your migrations are up to date and you don't ask for any unnamed variables, but you probably already know that.
SOLVED: Whilst I thought I had changed all the
{% load staticfiles %}
to
{% load static %}
I had missed one that was in an extended template that required this tag. Changing that too solved the issue. There was one other issue that was affecting this site and giving a Server Error (500) on another page too, and that is that in django 3.0, it looks like they are enforcing styling also, so I had to change:
{% static 'project_portal/images/icon_add_circle.png'%}
by adding a space between the last ' and the % so this:
{% static 'project_portal/images/icon_add_circle.png' %}
I am usually quite ocd about my styling but I missed this and it's now an issue in Django 3.
I am following the Symblog tutorial at http://tutorial.symblog.co.uk/,
and am stuck around the beginning of Chapter 2, just before the "Contact
Entity" section in the tutorial.
Instead of the contact form I'm supposed to view, I get this error message :
Unable to find template "BloggerBlogBundle:Page:contact.html.twig"
(looked into: app/Resources/views,
vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form).
500 Internal Server Error - InvalidArgumentException
1 linked Exception: Twig_Error_Loader
The template is located at src/Blogger/BlogBundle/Resources/views/Page/.
Why isn't Symfony looking for it in the right place ? This problem is all
the more mysterious to me as it does not occurr with another template
that's a "carbon copy" of contact.html.twig, namely about.html.twig.
The answers at Unable to find Twig template using render method in Symfony 2
and at Symfony cannot find the template file
suggest a typo in the template name, but that does not apply in my case.
I had this exact problem and ended up finding that on my Windows development machine the built in server did not care about capital letters in the filename path, it was NOT case sensitive. Then when I deployed my application to my remote server it was case-sensitive, I had one letter capitalized in a directory name which ended up wasting 30 minutes of my time.
I'm using Symfony2.4, and my question is:
- Symfony always tries exception and shows its error page
- But if my web faces 500 error, I want it to show default error page of nginx.
Can anybody help me?
Thanks in advance!
The kernel is catching exception like 500, or 404...
By default, he call TwigBundle:Exception:show controller, that will choose the template to use.
Create this folder.
app/Resources/TwigBundle/views/Exception
And add twig templates with the same name as TwigBundle's templates. They will override the default template.
I am using Symfony 2 framework and I am trying to re-direct my 404 page to another folder on my website. I am wondering how would I do this?
Currently, my 404 error page is located in app/resources/TwigBundle/views/Exception/error404.html.twig. I would like my 404 page to read from src/site/StoreBundle/Resources/views/pages/error404.html.twig.
Note that I only want to re-direct my 404 page. I still want my other errors (500, 503) to remain in app/resources/TwigBundle/views/Exception/error404.html.twig.
I'm not sure why you're wanting to do this so it's difficult to advise but why can't you just put an include in app/resources/TwigBundle/views/Exception/error404.html.twig which pulls in your other template? Be sure to use the correct namespace for your bundle. Something like the below should be fine (edit where appropriate).
{% include 'StoreBundle:pages:error404.html.twig' %}
How can I get a module to redirect if a user doesn't have the correct permissions to view it instead of getting the usual "Access denied. You are not authorized to access this page." message?
If it is a module you are writing yourself use the goto function of Drupal
http://api.drupal.org/api/function/drupal_goto
If you are not writing it yourself then it's a bit tougher, you can set the error redirects with Drupal and some modules however for a specific module I think you might have to go in and patch it in some way.
pretty much anything you wanna do to modify drupal stock behaviour can be handled via hook_nodeapi
Custom Error provides the ability to easily customize 403 and 404 error messages. With that, you could use drupal_goto() to automatically redirect users, or drupal_get_destination() to build a login link that will return the user to the page they attempted to view.
For more general, login-specific functionality, you might check out LoginToboggan.
The source code for both modules will also include useful examples of how to approach this problem space if you do not want the overhead or external dependency of a module.