4

I've been exploring and getting somewhat close to what I want (getting the value of the title attribute into my lightbox frame) by reading documentation and this topic here at Drupal Answers.

I'm working with a custom tpl.php file with the following code (copied from elsewhere):

   if($id == 'field_afbeelding') {
            $samples = explode(';', $fields['field_werken_afbeelding_sampl']->content);
            $originals = explode(';', $field->content);
            for($i = 0; $i < count($samples); $i++) {
                print l($samples[$i], $originals[$i], array('html' => TRUE, 'attributes' => array('rel' => 'lightbox')));
            }
        }

From what I gathered in the documentation, it appears that I need to insert the lightmodal[][] array-thing into my code right at the end, where it says array('rel' => 'lightbox').

In the Drupal Answers topic, the question starts off about how to insert a CCK field (or a caption or whatever) into a lightbox, but ends about how to get the title attribute.

The very last comment says - I quote : 'Type <pre><?php print_r($node); ?></pre> in node.tpl.php to see what's available in the node object (what fields, how formatted, etc.) and then take what you want and output it to the lightbox. I hope that's what you need..'

In my case, it's a view, so I went with devel module, going <?php global $field; dpm($fields);?>

Now as for 'take what you want and output it to the lightbox', the problem is I don't recognize out of these clickable Krumo blocks what I need. I do get these Krumo blocks that the devel module shows where you can click in the them and explore those elements/objects/whatever you want to call them.

I've been expanding all of the arrays and been seing 'title' in nested arrays. I guess the question boils down to what exactly must I put in this lightmodal[][] array if I'm right about the lightmodal thing?

And, before you ask, I made sure than in CCK, when editing the image field, I have alt and title attribute checkboxes checked and also given values to the images at hand.

  • what format are you using for your view - content or fields? it sounds like you are using a node template and then displaying the results in your view as nodes so the relevant values would be in the $node object and not views / fields specific. – schnippy Apr 24 '12 at 18:33
  • I'm using the fields format in my view. Is it normal that <?php global $node; dpm($node); ?> doesn't return anything? I get no errors either, just a blank green devel box. The name of my template file is views-view-fields--grafiek--page.tpl.php – Immers Apr 25 '12 at 7:55
1

There are multiple issues for Lightbox about your problem. Atm your best chance is indeed to override the relevant tpl.php file. This would be in the form of views-view-field--viewid--fieldname.tpl.php. The variables exposed in there that are of interest are the following:

  • $output: The processed output that will normally be used.
  • $row: The raw SQL result that can be used.

The first one indeed contains a string in the form of:

<a 
  href="http://www.example.com/sites/default/files/styles/large/public/img.png?itok=Tn9Y1Pyo" 
  rel="lightbox[field_image][]">
    <img 
      typeof="foaf:Image" 
      src="http://www.example.com/sites/default/files/styles/lines_thumbnail/public/img.png?itok=shRRK" alt="" />
</a>

The above should become something like this:

<a 
  href="http://www.example.com/sites/default/files/styles/large/public/img.png?itok=Tn9Y1Pyo" 
  rel="lightbox[field_image][<p>CAPTION</p>]">
    <img 
      typeof="foaf:Image" 
      src="http://www.example.com/sites/default/files/styles/lines_thumbnail/public/img.png?itok=shRRK" alt="" />
</a>

in order to have a caption in your lightbox.

You could of course use a replace function in order to achieve this, such as your attempted solution.

What I recommend is to use the $row variable to obtain the data itself and construct the output however you wish, for instance to add a title in <a> as well and why not solve the empty alt attribute value issue as well for the sake of SEO:

<?php
  //print $output; 
  //dpm($output); 
  //dpm($row);
  $caption = $row->taxonomy_term_data_name, // HERE use your field of choice
  print l(
    theme_image_style(array(
      'style_name' => 'thumbnail',
      'path' => $row->field_field_image[0]['raw']['uri'],
      'alt' => $caption,
      'attributes' => array('typeof' => 'foaf:Image'),
      'width' => NULL,
      'height' => NULL,
    )),
    image_style_url('large', $row->field_field_image[0]['raw']['uri']),
    array(
      'attributes' => array(
        'title' => $caption,
        'rel' =>
          'lightbox[field_image][<p>' . $caption . '</p>]',
      ),
      'html' => TRUE,
    )
  );
?>
| improve this answer | |
0

You're using Views 3, Drupal 7 and creating a view with a fields format so you want to be using the views-view-fields--VIEWNAME template for row style output (all of which looks good so far). The change is that because you're using fields and not node, you won't have access to your $node variables within the views template and you want to use the $fields array.

Assuming that the title you want to add to the lightbox attribute is the same as the title of your node (and assuming you probably want the plain text version) you could access it as:

print $fields["title"]->raw;

If that's not the field you want, you can scan the fields array using devel with this:

dsm($fields);
| improve this answer | |
  • Hi, if you check my (I admit a little long and clunky) question, you can see I already did a dpm($fields);. In the output of that dpm($fields);,the title attribute of the image is inside of a string that is the entire html of the image and not a key => value structure that could be used. – Immers Apr 27 '12 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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