Community & Support

Separating out individual nodes in $content variable of a teaser

I am almost finished a theme but am stuck as to how to get past the simple 'print $content' in node.tpl.php and actually be able to style the image and the text separately within $content further than with CSS (which won't do what I need).

I have run print_r($node) to see what's available within the node content but need someone to tell me how to make a simple print/echo command to produce the image and the text separately.

any help greatfully appreciated

cheers Rebekah

r($node) is producing the following output to the page (where it says 'Image of a map' is where the image actually appears on the page):

[nid] => 84
    [type] => article
    [language] =>
    [uid] => 1
    [status] => 1
    [created] => 1133395200
    [changed] => 1228471154
    [comment] => 2
    [promote] => 1
    [moderate] => 0
    [sticky] => 0
    [tnid] => 0
    [translate] => 0
    [vid] => 84
    [revision_uid] => 1
    [title] => ASKING FOR DIRECTIONS
    [teaser] =>
Image of a map

Abi Curtis

It’s mid-morning in the suburbs of Oxford. I’m turning around in an unfamiliar street, window wound down, heart-beat increased, a local telling me that, yes, he’s sure if I go left at the end of the road, and left again, I’ll find it. I’m almost there. Five minutes. There are at least eight cars behind me. I’m heaving the steering wheel around, backing into the dry leaves of a summer hedge. I’m almost there. It’s five minutes away. Everything will turn out alright.


    [log] =>
    [revision_timestamp] => 1228471154
    [format] => 2
    [name] => admin
    [picture] =>
    [data] => a:5:{s:14:"picture_delete";s:0:"";s:14:"picture_upload";s:0:"";s:7:"contact";i:1;s:13:"form_build_id";s:37:"form-eeec1e9888428995d77dadd30b80863f";s:18:"admin_compact_mode";b:1;}
    [field_magazine_article_author] => Array
        (
            [0] => Array
                (
                    [value] => Abi Curtis
                    [safe] => Abi Curtis
                    [view] => Abi Curtis
                )

        )

    [last_comment_timestamp] => 1227697520
    [last_comment_name] =>
    [comment_count] => 0
    [iid] => 161
    [parent] => 21
    [order_by] => 2
    [0] =>
    [taxonomy] => Array
        (
            [65] => stdClass Object
                (
                    [tid] => 65
                    [vid] => 3
                    [name] => Article
                    [description] => A type of content classified as an article.
                    [weight] => 0
                )

            [46] => stdClass Object
                (
                    [tid] => 46
                    [vid] => 5
                    [name] => Write
                    [description] => A community for students and graduates with an interest in writing for publication.
                    [weight] => 2
                )

        )

    [files] => Array
        (
        )

    [build_mode] => 0
    [readmore] => 1
    [content] => Array
        (
            [image_attach] => Array
                (
                    [#weight] => -10
                    [#value] =>
Image of a map


                    [#title] =>
                    [#description] =>
                    [#printed] => 1
                )

            [field_magazine_article_author] => Array
                (
                    [#context] => teaser
                    [#access] => 1
                    [#type_name] => article
                    [#field_name] => field_magazine_article_author
                    [#weight] => -3
                    [#post_render] => Array
                        (
                            [0] => content_field_wrapper_post_render
                        )

                    [field] => Array
                        (
                            [#description] =>
                            [items] => Array
                                (
                                    [0] => Array
                                        (
                                            [#formatter] => default
                                            [#node] => stdClass Object
*RECURSION*
                                            [#type_name] => article
                                            [#field_name] => field_magazine_article_author
                                            [#weight] => 0
                                            [#theme] => text_formatter_default
                                            [#item] => Array
                                                (
                                                    [value] => Abi Curtis
                                                    [safe] => Abi Curtis
                                                    [#delta] => 0
                                                )

                                            [#title] =>
                                            [#description] =>
                                            [#theme_used] => 1
                                            [#printed] => 1
                                            [#type] =>
                                            [#value] =>
                                            [#prefix] =>
                                            [#suffix] =>
                                            [#children] => Abi Curtis
                                        )

                                    [#title] =>
                                    [#description] =>
                                    [#children] => Abi Curtis
                                    [#printed] => 1
                                )

                            [#single] => 1
                            [#attributes] => Array
                                (
                                )

                            [#required] =>
                            [#parents] => Array
                                (
                                )

                            [#tree] =>
                            [#context] => teaser
                            [#page] =>
                            [#field_name] => field_magazine_article_author
                            [#title] => Author
                            [#access] => 1
                            [#label_display] => hidden
                            [#teaser] => 1
                            [#node] => stdClass Object
*RECURSION*
                            [#type] => content_field
                            [#children] => Abi Curtis
                            [#printed] => 1
                        )

                    [#title] =>
                    [#description] =>
                    [#children] =>
Abi Curtis


                    [#printed] => 1
                )

            [body] => Array
                (
                    [#weight] => -1
                    [#value] =>

It’s mid-morning in the suburbs of Oxford. I’m turning around in an unfamiliar street, window wound down, heart-beat increased, a local telling me that, yes, he’s sure if I go left at the end of the road, and left again, I’ll find it. I’m almost there. Five minutes. There are at least eight cars behind me. I’m heaving the steering wheel around, backing into the dry leaves of a summer hedge. I’m almost there. It’s five minutes away. Everything will turn out alright.


                    [#title] =>
                    [#description] =>
                    [#printed] => 1
                )

            [#title] =>
            [#description] =>
            [#children] =>
Image of a map

Abi Curtis

It’s mid-morning in the suburbs of Oxford. I’m turning around in an unfamiliar street, window wound down, heart-beat increased, a local telling me that, yes, he’s sure if I go left at the end of the road, and left again, I’ll find it. I’m almost there. Five minutes. There are at least eight cars behind me. I’m heaving the steering wheel around, backing into the dry leaves of a summer hedge. I’m almost there. It’s five minutes away. Everything will turn out alright.


            [#printed] => 1
        )

    [links] => Array
        (
            [comment_add] => Array
                (
                    [title] => Add new comment
                    [href] => comment/reply/84
                    [attributes] => Array
                        (
                            [title] => Add a new comment to this page.
                        )

                    [fragment] => comment-form
                )

            [node_read_more] => Array
                (
                    [title] => Read more
                    [href] => node/84
                    [attributes] => Array
                        (
                            [title] => Read the rest of ASKING FOR DIRECTIONS.
                        )

                )

        )

)

Comments

help!

can anyone help me with this issue?

rebekah

For more comprehensive

For more comprehensive control, use contemplate or use node-your_content_type.tpl.php in your theme folder to style/output however you want it.
Read http://drupal.org/node/17565

If you just want to style the image_attach, you can override theme_image_attach_teaser() or theme_image_attach_body() in your template.php.
Read http://drupal.org/node/173880

CK Ng | myFineJob.com
consultation • web design & development • content development • site domain, hosting & maintenance • software design & development

Fun stuff! You will need

Fun stuff! You will need the following modules to accomplish this:

CCK allows you to add custom fields to your content. So just like adding a title and body, Imagefield module allows you to upload images. Contemplate gives you a window to formatting the teaser, body and rss layout. Just like the print_r(content), contemplate allows you to click and add fields to the content template. For example, to display the body field only:
Body Template:

<?php print $node->content['body']['#value'] ?>

Pretty standard. Next, is a custom image field (image_caption) along with alternate text, is displayed right aligned with the body #value (so that the body text will wrap around the image):

<?php

// check if there is an image, else display nothing
if($node->field_image_caption[0]['filepath']) { ?>

 
<div class="inlineimage">
    <img src="<?php print base_path().$node->field_image_caption[0]['filepath'] ?>" alt="" hspace="4" vspace="4" />
    <?php print $node->field_image_caption[0]['alt'] ?>
  </div>

<?php } ?>

<?php print $node->content['body']['#value'] ?>

image_caption is the name of the image field I gave it.
Supporting CSS:
.inlineimage{
  margin-left:8px;
  margin-right:5px;
  color:#ccc;
  font-size:10px;
  float:right;
  display:block;
  width:300px;
  height:auto;
}

You can access $node->blah in node.tpl.php. The downside is, the teasers and full text will have the same layout, unless you put a conditional statement. Its far easier using CCK and contemplate.