Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8356141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:05:41+00:00 2026-06-09T10:05:41+00:00

I know that this question is perfectly answered in FOSUserBundle documentation, but yet I

  • 0

I know that this question is perfectly answered in FOSUserBundle documentation, but yet I can’t solve my problem.

I am trying to make an own login page using FOSUserBundle.

I have a main.html.twig that is EXACTLY the same as the login.html.twig included in the FOSUserBundle source.

The only difference is that main.html.twig is in my own bundle structure and login.html.twig is in FOSUserBundle folder structure.

I reach both /login and /main. I resolve them and the render starts.

But when accessing /main, I get the following error:

Twig_Error_Runtime: Variable “csrf_token” does not exist in “AcmeStoreBundle:Main:main.html.twig” at line 5

The code is known by the FOSUserBundle users, but anyway I paste it here:

<form action="{{ path("fos_user_security_check") }}" method="post">
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />

<label for="username">{{ 'security.login.username'|trans({}, 'FOSUserBundle') }}</label>
<input type="text" id="username" name="_username" value="" />

<label for="password">{{ 'security.login.password'|trans({}, 'FOSUserBundle') }}</label>
<input type="password" id="password" name="_password" />

<input type="checkbox" id="remember_me" name="_remember_me" value="on" />
<label for="remember_me">{{ 'security.login.remember_me'|trans({}, 'FOSUserBundle') }}</label>

<input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}" />

The variable “csrf_token” is somehow not recognized from outside FOSUserBundle. Or something else that I am not getting.

Any clue over there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:05:42+00:00Added an answer on June 9, 2026 at 10:05 am

    Since you are not using FormBuilder, in your action that is responsible for rendering main.html.twig you should generate this token and pass it to the View.

    $csrf = $this->get('form.csrf_provider'); //Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider by default
    $token = $csrf->generateCsrfToken($intention); //Intention should be empty string, if you did not define it in parameters
    

    You should pass $token as csrf_token variable to your View

    Check also my answer to similar question

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this question must have been asked and answered a million times,
I know that this sort of question has been asked here before, but still
I know that this is a newbie question but I am a newbie so
I know that this may be an amateur question but for some reason I
Well I know that this question may be asked many times but certainly I've
I know that this question had already been asked a couple of times before,
I know that this question is asked a lot, I checked all of the
I know that this question is very similar to the question posted here .
I know that this question has been asked several times and I've read all
I know that this is a repeated question. I have found very similar questions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.