<p>I usually like to use the <code>.find()</code> method and then you can pass in an object in your twig with criteria for the query. This is an example of eager-loading and relatedTo.</p>

<pre><code>{% set entries = craft.entries.find({
    section: 'articles',
    with: ['featuredImage'],
    limit: 4,
    relatedTo: category
}) %}
</code></pre>

<p>Let me know if this helps at all otherwise I'd be happy to dig into your use case more.</p>

CC BY-SA 3.0
2018-01-22T15:14:16.397Z
2018-01-22T16:39:42.313Z
2018-01-22T16:39:42.313Z
mcclaskiem
<p>For a website I'm building for a client I've build a navigation where on hover an image changes dynamically to the image assigned to the entry. See this page for a better understanding: <a href="http://sandmandance.com/dev/projects/performance" rel="nofollow noreferrer">http://sandmandance.com/dev/projects/performance</a></p>

<p>It all works fine but at first page load the images are only loading when hovering over the navigation which causes a small glitch. What I'd like to do (and seems like the easiest solution) is to load all the assets on page load using Eager-Loading.</p>

<p>Thing is.. I can't seem to combine it with relatedTo(category). So in short; how can I combine Eager-Loading and relatedTo(category) in a way it works?</p>

<relatedto><eager-loading>
Combine Eager-Loading and relatedTo(category)
# Combine Eager-Loading and relatedTo(category)

(Asked by: username_0 on 2018-01-22)

For a website I'm building for a client I've build a navigation where on hover an image changes dynamically to the image assigned to the entry. See this page for a better understanding: <http://sandmandance.com/dev/projects/performance>

It all works fine but at first page load the images are only loading when hovering over the navigation which causes a small glitch. What I'd like to do (and seems like the easiest solution) is to load all the assets on page load using Eager-Loading.

Thing is.. I can't seem to combine it with relatedTo(category). So in short; how can I combine Eager-Loading and relatedTo(category) in a way it works?

**Tags:** relatedto, eager-loading

---

## 1 answers

### Answer by username_1 on 2018-01-22. Score: 1

I usually like to use the .find() method and then you can pass in an object in your twig with criteria for the query. This is an example of eager-loading and relatedTo.
{% set entries = craft.entries.find({
    section: 'articles',
    with: ['featuredImage'],
    limit: 4,
    relatedTo: category
}) %}

Let me know if this helps at all otherwise I'd be happy to dig into your use case more.


---

