0

I need to add id tag to an image which is a field of a view. Currently it seems only possible to add a class name.

<img typeof="foaf:Image" ... must become => <img id="xxx" typeof="foaf:Image" ...

5
  • Can't remember off-hand which tpl it is, maybe views-view-fields.tpl.php. Edit that (or the correct one) for your field to add the CSS ID to the html and then use the appropriate preprocess to add the $css_id var to it.
    – sareed
    Commented Dec 22, 2015 at 19:40
  • In html id's have to be unique. Why not use unique classes? same result...
    – No Sssweat
    Commented Dec 22, 2015 at 19:54
  • @No Sssweat: Class is an option if there is no other solution, but getElementByClassName is less supported by browsers than getElementById.
    – Pierre_C
    Commented Dec 22, 2015 at 20:09
  • @sareed: I checked in views template, but not found.
    – Pierre_C
    Commented Dec 22, 2015 at 20:10
  • @Pierre_C how many rows does your view have? If more than 1, you have to keep in mind that you will need to use some variable in your id, or else all your rows will have the same id, which is a nono.
    – No Sssweat
    Commented Dec 22, 2015 at 20:14

1 Answer 1

1

Searching for typeof="foaf:image" I found that was set by rdf module preprocess_image, not in views. Therefore I added a preprocess function

function MYTHEME_preprocess_image(&variables){
  // compute first MY_UNIQUE_ID
  $variables['attributes']['id'] = array('MY_UNIQUE_ID');
}

now it works.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.