<p>There are two issues with your code:</p>
<ol>
<li><p>You aren't able to reference <code>entry</code> in the field. <a href="https://craftcms.com/docs/4.x/entries.html#dynamic-entry-titles" rel="nofollow noreferrer">This section</a> in the docs describes the rules around using Twig in the Entry title field, and the same rules apply in this case as well. The long and short of it is you can either use the shortcut syntax and forego referencing the entry at all: <code>{site.slug}</code>, or you can use the normal syntax, in which case you'll want to use the <code>object</code> variable to refer to the current entry: <code>{{ object.site.slug }}</code>.</p>
</li>
<li><p>Secondly, Sites don't have slugs (you can see all possible variables <a href="https://docs.craftcms.com/api/v4/craft-models-site.html" rel="nofollow noreferrer">here</a>). My suggestion would be to use the Site's handle instead, and maybe throw the <a href="https://craftcms.com/docs/4.x/dev/filters.html#kebab" rel="nofollow noreferrer"><code>kebab</code> filter</a> on it so it looks better (<code>/path/to/images/my-lovely-site</code> instead of <code>/path/to/images/myLovelySite</code>):</p>
<pre><code>{site.handle|kebab}

{# or {{ object.site.handle|kebab }} #}
</code></pre>
</li>
</ol>

CC BY-SA 4.0
2024-02-14T21:18:21.703Z
I pushed a page for the 5.x docs on [object templates](https://craftcms.com/docs/5.x/system/object-templates.html), but haven't back-ported it to the 4.x docset just yet!
August Miller
CC BY-SA 4.0
2024-02-15T10:45:03.450Z
Yes it works ! thank you !
emilie zawadzki
CC BY-SA 4.0
2024-02-22T12:28:05.103Z
It works but.... if you have a multilingual site, you'll have to upload two times the assets.
So I needed to slice the last letter of my site handle (mySiteFR, mySiteEN...) which correponds to the letter of the language (FR, EN, DE...).
Here the solution : {site.handle|kebab|substr(0,-2)}
emilie zawadzki
CC BY-SA 4.0
2024-02-14T19:11:01.337Z
2024-02-14T19:11:01.337Z
Jalen Davenport
<p>In Craft 4.7.2.1 Pro, I try to create dynamic path location for my assets for my field &quot;image&quot;.
The field image is in MySection, which is shared with multiple sites.</p>
<p>I would like to organize images in separate folders for each site. I tried something like :</p>
<pre><code>{entry.site.slug}
</code></pre>
<p>but doesn't work</p>

<assets><assets-field>
Assets dynamic location functions of site
# Assets dynamic location functions of site

(Asked by: username_0 on 2024-02-13)

In Craft 4.7.2.1 Pro, I try to create dynamic path location for my assets for my field "image".
The field image is in MySection, which is shared with multiple sites.
I would like to organize images in separate folders for each site. I tried something like :
{entry.site.slug}

but doesn't work

**Tags:** assets, assets-field

---

## 1 answers

### Answer by username_1 on 2024-02-14. Score: 2 | Accepted answer

There are two issues with your code:

You aren't able to reference entry in the field. This section in the docs describes the rules around using Twig in the Entry title field, and the same rules apply in this case as well. The long and short of it is you can either use the shortcut syntax and forego referencing the entry at all: {site.slug}, or you can use the normal syntax, in which case you'll want to use the object variable to refer to the current entry: {{ object.site.slug }}.

Secondly, Sites don't have slugs (you can see all possible variables here). My suggestion would be to use the Site's handle instead, and maybe throw the kebab filter on it so it looks better (/path/to/images/my-lovely-site instead of /path/to/images/myLovelySite):
{site.handle|kebab}

{# or {{ object.site.handle|kebab }} #}

> **Comments:**
> **username_2**: I pushed a page for the 5.x docs on [object templates](https://craftcms.com/docs/5.x/system/object-templates.html), but haven't back-ported it to the 4.x docset just yet!  
> **username_0**: Yes it works ! thank you !  
> **username_0**: It works but.... if you have a multilingual site, you'll have to upload two times the assets. So I needed to slice the last letter of my site handle (mySiteFR, mySiteEN...) which correponds to the letter of the language (FR, EN, DE...). Here the solution : {site.handle|kebab|substr(0,-2)}  

---

