How I (finally) got captions to display.

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Dave R.'s picture

This is how I added captions, or cutlines, to the Articles content type in Openpublish. I hope that it is helpful to anyone who, like me, spent untold hours trying to figure it out.

First, add a field to the Article content type (../admin/content/node-type/article/fields). I labelled mine Caption and gave it the name field_main_image_caption. I chose Text for the field type and gave it a textfield size of 200.

Next, add something like: $vars['main_image_caption'] = $vars['field_main_image_caption'][0]['view'];
to node-article.tpl.inc below the // Main_image notation. (Here, I think I was a bad boy and changed the file in sites/all/modules/openpublish_core/theme_helpers because I was not sure if the override would work if I put my new version of the .inc file in my subtheme folder. I'll get around to looking at this at some point.)

Then it was time to edit my subtheme's node-article.tpl.php to display the caption. All I did was add <?php print $main_image_caption; ?> to the following:

if ($main_image): ?>
    <div class="main-image">
      <?php print $main_image; ?>
        <div class="main-image-desc image-desc">
          <?php print $main_image_caption; ?>
          <span class="main-image-credit image-credit"><?php print $main_image_credit; ?></span>
        </div><!-- /.main-image-desc -->
    </div><!-- /.main-image -->
  <?php endif; ?>

After that, I added a caption to an article and changed my CSS for image-desc in components.css to something I liked.

That's it. Please let me know if I have written anything crazy that needs to be corrected, and I will edit the instructions.

Comments

So, you took out image

jaarong's picture

So, you took out image description in favor of cutlines? What's the difference?

Well, at least on my

Dave R.'s picture

Well, at least on my installation of OP, the image description appeared only as a tooltip when a user hovered over an image. I wanted a traditional caption that always appeared below the image. By adding the Caption field, I now have a separate display that I can style or do whatever I want with.

This is great news. But if

ithacaindy's picture

This is great news. But if you are using OpenPublish, captions are already enabled, right?

subtheme

ShedPhotons's picture

Also, was this a custom sub-theme or one that came with OP?

where is template?

ShedPhotons's picture

Which version of OpenPublish does this refer to? I am using the D7 alpha release and don't see node-article.tpl.php anywhere. I am doing something similar using field.tpl.php instead, but the caption is stored in either #markup or #children, separately from other image data, and I can't figure out how to access it. It would be possible to use $item['#item']['alt'] or the title, but we want to include extra information, so a text area like the caption is needed. Here is a relevant snippet from print_r:

   Array
(
    [#markup] =>

The caption is here.


    [#printed] => 1
    [#type] => markup
    [#pre_render] => Array
        (
            [0] => drupal_pre_render_markup
            [1] => ctools_dependent_pre_render
        )

    [#children] =>

The caption is here.

)

OpenPublish

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week