Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

Media url in multilingual site

Started by nix 8 years ago · 2 replies · 547 views
8 years ago

Hello,

I have a problem accessing the url of the first image to define twitter card image. I have a multilingual site (en + fr). When I do:
<meta name="twitter:image" property="twitter:image" content="{{ base_url_absolute }}{{ page.media.images|first.url(true) }}" />

It gives me for example:
http://nimon.org/fr/user/pages/35.axismvndi/axis1.jpg
instead of:
http://nimon.org/user/pages/35.axismvndi/axis1.jpg

There is the 'fr' code in the url. How can I have the right url?
Thanks in advance,

Nicolas

8 years ago

The language suffix was actually in base_url_absolute so I hardcoded the base url.

8 years ago

@nix

You have a few options as to where to store and how to fetch your images:

  • Next to the page as you do now.
    page.media.images|first.url will return /user/pages/35.axismvndi/first-image.jpg.
  • You could place all images together in user/pages/images.
    See Where to put your media files
    • page.find('/images').media.images|first.url will return /user/pages/images/first-image.jpg.
    • page.find('/images').media['image.jpg'].url will return /user/pages/images/image.jpg
    • media_directory('page://images').images|first.url will return /user/pages/images/first-image.jpg
  • Or you could place all media in user/themes/mytheme/images:
    media_directory('theme://images').images|first.url will return /user/themes/my-theme/images/axis1.jpg
    See Media Directory

All options will return a url starting with /user/pages/... or /user/themes/... which will be translated to the correct url in the browser. No need to add http://nimon.org manually.

Hope this helps.

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 57 15 hours ago
Support · by Anna, 3 days ago
2 65 18 hours ago
Support · by Justin Young, 18 hours ago
1 33 18 hours ago
Support · by Duc , 1 week ago
2 68 5 days ago
Support · by Colin Hume, 1 week ago
2 60 6 days ago