0

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 %}
1

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 set up in the control panel, or

  2. 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 docs are a good place to start to understand how all of this works.

  • Yes it was in a routes.php file in config/. Thanks! – asebold Nov 14 '16 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.