Forum

Thread tagged as: Question, Api

Ho can I access/use the image file name in the template


<a href='#IMAGEFILE' title='<perch:content id="bildtitel" label="Titel" type="text" />' class="image-modal">
    <img src='<perch:content id="bild" label="Bild" type="image" />'
     alt='<perch:content id="bildtitel" label="Titel" type="text" />'></a>

if the uploaded image is located at perch/resources/nicepicture.jpg, I would like the href of the surrounding anchor to be #nicepicture

Volker Kopetzky

Volker Kopetzky 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

If you upload the image using a Perch Image tag then the URL of the image is exactly what you get back.

Have a look at the docs here: https://docs.grabaperch.com/docs/templates/attributes/type/image/

yes. but there's no output but the URI.

Is there another way to 'go PHP' and to get the filename from the string? Or is it easy to extend perch to add another output option?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

I don't understand what you are trying to do. What is #nicepicture linking to?

The href will be used by javascript and needs to point to the ID of the image, corrected code:

<a href='#IMAGEFILE' title='<perch:content id="titel" label="Titel" type="text" />'>
    <img id="IMAGEFILE" src='<perch:content id="bild" label="Bild" type="image" />'
     alt='<perch:content id="titel" label="Titel" type="text" />'></a>

Also, the snippet is part of a perch:block, which also implies unique IDs. For this, I already found the perch_item_index attribute that I could use create unique IDs

Unless there is an easy way to use the image filename instead I would suggest to save your time and just close this ticket.

PS: Apologies for the misunderstandings, I'm still learning the ways of the perch.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Try:

<perch:content id="bild" type="image" replace="/perch/resources/|,.jpg|,.png|,.gif|" />

ouch! why wander so far if the replace is so close.....

Thanx!