<p>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?</p>

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

<pre><code>{% for block in entry.myMatrixField %}
    {% if block.type == "something" %}
        {% if block.entry.status != 'expired' %}
            {{ block.entry.title}}
        {% endif %}
    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-02-15T16:28:58.663Z
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
CC BY-SA 3.0
2017-02-15T16:20:32.033Z
2017-02-15T16:20:32.033Z
Tom De Smet
<p>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.</p>

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

CC BY-SA 3.0
2017-02-15T15:38:48.023Z
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
CC BY-SA 3.0
2017-02-15T16:11:18.290Z
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
<routes><controller>
How do I set a controller for my homepage
# How do I set a controller for my homepage

(Asked by: username_0 on 2017-02-15)

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.

**Tags:** routes, controller
> **Comments:**
> **username_1**: 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.  
> **username_0**: 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)  

---

## 1 answers

### Answer by username_1 on 2017-02-15. Score: 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 %}

> **Comments:**
> **username_0**: 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 %}  

---

