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

Image from Admin panel in Twig template?

Started by Muut Archive 10 years ago · 3 replies · 469 views
10 years ago

I added a special image file upload field to my admin panel, but I can't seem to access the uploaded image URL in Twig. The .image object returns an array that appears to be inaccessible in Twig:

JS
array:1 [
  "user/pages/images/D2031.jpg" => array:4 [
    "name" => "D2031.jpg"
    "type" => "image/jpeg"
    "size" => 59409
    "path" => "user/pages/images/D2031.jpg"
  ]
]

object.image.name = null

10 years ago

I suppose you do not upload the files to the page folder itself (destination: 'self@'), but to a specific folder (destination: 'page@:/images) ?
If you know the path to that folder you can use its page.media:

TWIG

 {% set image_page = page.find('/images') %}

{{ image_page.media[object.image].html() }} 
{{ image_page.media[object.image].url }}
{{ image_page.media[object.image].cache.url }}
10 years ago

Is that path relative to the partials folder?

And yes, the images are in user/pages/images/

10 years ago

I don't really understand your question. The path is relative to the root.

TXT

page.find('whatever') >> checks basically your pages folder (user/pages/) for a page or folder 'whatever'

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1359 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2955 9 years ago
Archive · by Muut Archive, 9 years ago
3 1121 9 years ago