0

How can I set a controller for the homepage? I can't seem to find any way to override the default route to the homepage. I need to call an action from the homepage and can't find any examples of this can be done.

I have a matrixfield with entries in them and want to filter out the matrix blocks that have expired entries on the homepage.

  • So you just want to show all non-expired entries on your homepage? Can you be more specific? I'm guessing that you don't need a plugin for what you are trying to achieve here. I could be wrong of course, I would need some more information. – Tom De Smet Feb 15 '17 at 15:38
  • Yes, the problem is, if there's a block that contains an entry, it will show up regardless of if the entry has since expired and thus be empty. (The blocks only contain a single entry, i'm using a matrix simply so that the entries order can be sorted manually with the drag and drop feature of the matrix field) – Robert Feb 15 '17 at 16:11
1

Ok, maybe you can check if the entry in the matrix block is still valid (non-expired) and if that's not the case, just don't render the matrix block? Put everything in a simple if statement?

Something like this (hasn't been tested, use it as an example of what the actual code would be):

{% for block in entry.myMatrixField %}
    {% if block.type == "something" %}
        {% if block.entry.status != 'expired' %}
            {{ block.entry.title}}
        {% endif %}
    {% endif %}
{% endfor %}
  • Yes that would work, but the thing I didn't mention is that I am then passing the blocks to a twig macro in sections, so the first 6 entries, then a special other entry, then the next 6. So that logic didn't quite work for me. But I did find another approach that does work using relatedTo: <code> {% for block in entry.homepageTiles %} {% set relatedEntries = relatedEntries|merge(craft.entries.section('events, offers, branches, articles, twitter').relatedTo(block)) %} {% endfor %} – Robert Feb 15 '17 at 16:28

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.