Body: <p>I am trying to create a seamless user login interaction with a modal form using ajax. Let's say I have a navigation template <code>_navigation.html</code></p>
  
  <pre><code>&lt;div&gt;
      {% if currentUser %}
      {{ currentUser }}
      — &lt;a href="{{ url('shop/customer') }}"&gt;{{ "My Orders"|t }}&lt;/a&gt;
      — &lt;a href="{{ url('shop/customer/addresses') }}"&gt;{{ "My Addresses"|t }}&lt;/a&gt;
      — &lt;a href="{{ url('shop/customer/cards') }}"&gt;{{ "My Cards"|t }}&lt;/a&gt;
      — &lt;a href="{{ logoutUrl }}"&gt;Logout&lt;/a&gt;
      {% else %}
        &lt;a href="" data-toggle="modal" data-target="#loginModal"&gt;{{ "Login"|t }}&lt;/a&gt;
      — &lt;a href="" data-toggle="modal" data-target="#registerModal"&gt;{{ "Register"|t }}&lt;/a&gt;
      {% endif %}
  &lt;/div&gt;
  </code></pre>
  
  <p>After successful login I would like to refresh the view by loading the template again (using <a href="http://api.jquery.com/load/" rel="nofollow noreferrer">jquery.load()</a>). Since the template is "hidden" I can't access it. If I make the template "visible" all works, but naturally I would like the template to stay "hidden".</p>
  
  <p>Is there any way to achieve this?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-20T12:03:26.597Z
Comments.Text: I would suggest you to create a custom controller that returns the required html together with the login response. Otherwise you would have to do a dirty work around via 2 ajax requests
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-20T12:17:59.443Z
Comments.Text: Cool, thanks. I will look into custom controllers. What do you mean with 2 ajax requests?
Comments.UserDisplayName: krizajb
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-20T12:27:44.600Z
Comments.Text: Some people prefer to now use PHP at all. So a (pretty bad) work around would be to create a second ajax request to your template and insert the result in your container
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-20T12:31:01.490Z
Comments.Text: Do you think "hidden" template would be accessible via ajax?
Comments.UserDisplayName: krizajb
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-20T12:32:58.110Z
Comments.Text: When you create a custom route yes
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-20T12:35:43.007Z
Comments.Text: But does it only make it accessible via ajax or does it become public? I would assume making a second ajax request is a lot slower then returning html with custom controller in first step?
Comments.UserDisplayName: krizajb
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-20T12:38:18.933Z
Comments.Text: It will be public... That's why I always prefer a controller
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-20T12:45:24.610Z
Comments.Text: OK, thank you. I would recommend you making an answer out of this conversation. If not, I will answer it myself once I'm done with the custom controller and make it work :)
Comments.UserDisplayName: krizajb
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-21T08:21:29.367Z
Comments.Text: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/77784/discussion-between-krizajb-and-robin-schambach).
Comments.UserDisplayName: krizajb
Tags: <templating><ajax><login>
Title: Refresh "hidden" template after login with ajax
ThreadText: # Refresh "hidden" template after login with ajax
  
  (Asked by: username_0 on 2018-05-20)
  
  I am trying to create a seamless user login interaction with a modal form using ajax. Let's say I have a navigation template `_navigation.html`
  
  ```
  <div>
      {% if currentUser %}
      {{ currentUser }}
      — <a href="{{ url('shop/customer') }}">{{ "My Orders"|t }}</a>
      — <a href="{{ url('shop/customer/addresses') }}">{{ "My Addresses"|t }}</a>
      — <a href="{{ url('shop/customer/cards') }}">{{ "My Cards"|t }}</a>
      — <a href="{{ logoutUrl }}">Logout</a>
      {% else %}
        <a href="" data-toggle="modal" data-target="#loginModal">{{ "Login"|t }}</a>
      — <a href="" data-toggle="modal" data-target="#registerModal">{{ "Register"|t }}</a>
      {% endif %}
  </div>
  
  ```
  
  After successful login I would like to refresh the view by loading the template again (using [jquery.load()](http://api.jquery.com/load/)). Since the template is "hidden" I can't access it. If I make the template "visible" all works, but naturally I would like the template to stay "hidden".
  
  Is there any way to achieve this?
  
  **Tags:** templating, ajax, login
  
  > **Comments:**
  > **username_1**: I would suggest you to create a custom controller that returns the required html together with the login response. Otherwise you would have to do a dirty work around via 2 ajax requests  
  > **username_0**: Cool, thanks. I will look into custom controllers. What do you mean with 2 ajax requests?  
  > **username_1**: Some people prefer to now use PHP at all. So a (pretty bad) work around would be to create a second ajax request to your template and insert the result in your container  
  > **username_0**: Do you think "hidden" template would be accessible via ajax?  
  > **username_1**: When you create a custom route yes  
  > **username_0**: But does it only make it accessible via ajax or does it become public? I would assume making a second ajax request is a lot slower then returning html with custom controller in first step?  
  > **username_1**: It will be public... That's why I always prefer a controller  
  > **username_0**: OK, thank you. I would recommend you making an answer out of this conversation. If not, I will answer it myself once I'm done with the custom controller and make it work :)  
  > **username_0**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/77784/discussion-between-username_0-and-username_1-username_1).  
  
  ---
  
  ## 0 answers
  
  