I'm working on a site that will end up having 30-40+ structure sections which are sharing templates and will be using about 10 different entry types.

(This would probably be much easier if I used categories instead of this many sections, but I need different user privileges for each 'project' and it seems there's no simple way to restrict users to editing specific categories. Creating a plugin is beyond my skills at the moment, so I have to make do with what I have...)

At the moment I'm using URL segments with getSegment to figure out which section is requested and I'm following this advice from the Craft help site to assign templates to entry types and I'm wondering if this practice has any effect on performance.

Basically it goes like this:

First I need to figure out which section I'm in based on the URL so I can fetch the correct entries. The beginning of my index.php looks like this:

{# Figure out which project/entry type is requested: #}

{% set projectSegment = craft.request.getSegment(1) %}
{% set entryType = craft.request.getSegment(2) %}

{% switch projectSegment %}
  {% case "myproject1" %}
    {% set projectSection = 'myProject1' %}
    {% set projectName = 'My Project 1' %} {# To be used later in templates #}
  {% case "myproject2" %}
    {% set projectSection = 'myProject2' %}
    {% set projectName = 'My Project 2' %}
{% endswitch %}

{# Fetch entries in the correct section using these variables: #}

{% set typePath = craft.entries.section(projectSection).type(entryType) %}

So now in my templates I can use this:

<h1>{{ projectName }}</h1>

{% for entry in typePath %}
{% endfor}

Then I have to assign each entry type to its own templates, so in the CP I'm pointing each section to a single entry.html template which looks like this:

{% block content %} 
  {% include "_projects/entry-types/" ~ entry.type %}
{% endblock %}

and in some cases I'm using even more conditionals in a particular entry type template to point to other templates:

{% switch entryType %}

  {% case 'entryType1' %}
    {% include '_project/entry-types/entryType1-listing' %}

  {% case 'entryType2' %}
    {% include '_project/entry-types/entryType2-listing' %}

{% endswitch %}

So here's my question:

Will the use of this many structures/entry types and the use of getSegment variables affect performance in any way, and will cache still perform efficiently?

From what I figured out, the {% cache %} tag should be placed inside the {% block %} tag, but since everything is 'dynamic' inside the {% block %} tag and changes based on the URL, I don't know if the cache will work the same way for all sections and entry types.

To complicate things even further, this will end up being multilingual as well, and I'm concerned this will put a lot of strain on the server.

Thanks in advance, any clarification is much appreciated.


Your Answer

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

Browse other questions tagged or ask your own question.