Answers.Body: <p>It looks like a custom route has been set up for <code>/updates/q</code> which points to the <code>updates/index.html</code> template.</p>
  
  <p>There are two places this could have been configured:</p>
  
  <ol>
  <li><p><a href="https://craftcms.com/docs/routing#dynamic-routes" rel="nofollow noreferrer">Dynamic routes</a> set up in the control panel, or</p></li>
  <li><p><a href="https://craftcms.com/docs/routing#advanced-routing" rel="nofollow noreferrer">Advanced routing</a> set up in the <code>routes.php</code> file.</p></li>
  </ol>
  
  <p>Look in both of those places to see if a custom route has been set up for <code>/updates/q</code>. If so, you will need to set up a similar one for <code>/blog/q</code> so that Craft knows which template to render for those requests.</p>
  
  <p>Craft's <a href="https://craftcms.com/docs/routing" rel="nofollow noreferrer">routing</a> docs are a good place to start to understand how all of this works.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-14T17:14:31.883Z
Answers.Text: Yes it was in a routes.php file in config/. Thanks!
Answers.UserDisplayName: asebold
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-14T12:31:46.853Z
Answers.LastActivityDate: 2016-11-14T12:31:46.853Z
Answers.UserDisplayName: Steve Rowling
Body: <p>Background: I've inherited a site built in craft that has a page called "updates" with a button to load additional entries through ajax. The updates page is an entry in the "page" structure and when it's template is called it loads entries stored in a channel also called "updates". The template the "pages" structure points to is pages/_entry.html, and this holds the logic for gathering entries stored in the "updates" channel. However, the ajax script calls /updates/q?param=1 which is somehow calling the template updates/index.html. All while the channel is set to call template entries/_entry.html for the individual entries in the channel.  </p>
  
  <p>So I tried to create a blog page that would work the same way. I created an entry in the "pages" structure called blog, then created the template blog/index.html which is the same as updates/index.html. The ajax script calls /blog/q?param=1 but it returns a 404. I even created a channel in the cms called blog wondering if that was the case but it hasn't helped. What does the url need to be to return blog/index.html?</p>
  
  <p>pages/_entry.html</p>
  
  <pre><code>{% extends "_layout" %}
  {% block content %}
  {% set myJs %}
  window.entryType = '{{ entry.type }}';
  {% endset %}
  
  {% includeJs myJs %}
  {% cache unless craft.config.devMode %}
  
    {% if entry.type != 'contact' %}
      {% include ['_partials/_page-header-' ~ entry.type, '_partials/_page-header'] %}
    {% endif %}
  
    {% include ['_partials/_page-content-' ~ entry.type, '_partials/_page-content' ] %}
  
  {% endcache %}
  {% endblock %}
  </code></pre>
  
  <p>updates/index.html</p>
  
  <pre><code>{% if craft.request.isAjax %}
    {% set layout = "_ajax" %}
  {% else %}
    {% set layout = "_layout" %}
  {% endif %}
  
  
  {% extends layout %}
  {% set title = 'Updates' %}
  {% block content %}
  
  {% cache for 3 hours unless craft.config.devMode %}
    {% if craft.request.isAjax %}
      {% include '_partials/_get-updates' %}
    {% else %}
      {% set entry = craft.entries.slug('updates').featuredUpdate %}
  
      &lt;section class="l-section u-bg--light-gray"&gt;
        &lt;div class="l-container"&gt;
          {% include '_partials/_updates-filter' %}
          {% include '_partials/_grid-cards' %}
          &lt;div class="l-section__cta"&gt;
            &lt;a href="#" class="btn btn--large" id="load-more"&gt;Load More&lt;/a&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/section&gt;
    {% endif %}
  
  {% endcache %}
  {% endblock %}
  </code></pre>
  
Tags: <templating><ajax><routing>
Title: Can't get correct template for ajax call
ThreadText: # Can't get correct template for ajax call
  
  (Asked by: username_0 on 2016-11-11)
  
  Background: I've inherited a site built in craft that has a page called "updates" with a button to load additional entries through ajax. The updates page is an entry in the "page" structure and when it's template is called it loads entries stored in a channel also called "updates". The template the "pages" structure points to is pages/\_entry.html, and this holds the logic for gathering entries stored in the "updates" channel. However, the ajax script calls /updates/q?param=1 which is somehow calling the template updates/index.html. All while the channel is set to call template entries/\_entry.html for the individual entries in the channel.
  
  So I tried to create a blog page that would work the same way. I created an entry in the "pages" structure called blog, then created the template blog/index.html which is the same as updates/index.html. The ajax script calls /blog/q?param=1 but it returns a 404. I even created a channel in the cms called blog wondering if that was the case but it hasn't helped. What does the url need to be to return blog/index.html?
  
  pages/\_entry.html
  
  ```
  {% extends "_layout" %}
  {% block content %}
  {% set myJs %}
  window.entryType = '{{ entry.type }}';
  {% endset %}
  
  {% includeJs myJs %}
  {% cache unless craft.config.devMode %}
  
    {% if entry.type != 'contact' %}
      {% include ['_partials/_page-header-' ~ entry.type, '_partials/_page-header'] %}
    {% endif %}
  
    {% include ['_partials/_page-content-' ~ entry.type, '_partials/_page-content' ] %}
  
  {% endcache %}
  {% endblock %}
  
  ```
  
  updates/index.html
  
  ```
  {% if craft.request.isAjax %}
    {% set layout = "_ajax" %}
  {% else %}
    {% set layout = "_layout" %}
  {% endif %}
  
  {% extends layout %}
  {% set title = 'Updates' %}
  {% block content %}
  
  {% cache for 3 hours unless craft.config.devMode %}
    {% if craft.request.isAjax %}
      {% include '_partials/_get-updates' %}
    {% else %}
      {% set entry = craft.entries.slug('updates').featuredUpdate %}
  
      <section class="l-section u-bg--light-gray">
        <div class="l-container">
          {% include '_partials/_updates-filter' %}
          {% include '_partials/_grid-cards' %}
          <div class="l-section__cta">
            <a href="#" class="btn btn--large" id="load-more">Load More</a>
          </div>
        </div>
      </section>
    {% endif %}
  
  {% endcache %}
  {% endblock %}
  
  ```
  
  **Tags:** templating, ajax, routing
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-14. Score: 1 | Accepted answer
  
  It looks like a custom route has been set up for `/updates/q` which points to the `updates/index.html` template.
  
  There are two places this could have been configured:
  
  1. [Dynamic routes](https://craftcms.com/docs/routing#dynamic-routes) set up in the control panel, or
  2. [Advanced routing](https://craftcms.com/docs/routing#advanced-routing) set up in the `routes.php` file.
  
  Look in both of those places to see if a custom route has been set up for `/updates/q`. If so, you will need to set up a similar one for `/blog/q` so that Craft knows which template to render for those requests.
  
  Craft's [routing](https://craftcms.com/docs/routing) docs are a good place to start to understand how all of this works.
  
  > **Comments:**
  > **username_0**: Yes it was in a routes.php file in config/. Thanks!  
  
  ---
  
  