Solved

tpl issue with getting an image to show

Posted on 2011-03-19
2
394 Views
Last Modified: 2012-05-11
The code in question is in <!--item-pic-->  I pull in the subcat field (body) from the db and I have added an image field called field_imagesc and I am trying to get it to display but I get a blank output (seen here: http://tinyurl.com/6lxhxww).

<?php
$acount = count($node->field_subcats);
if($acount == 1){
     drupal_goto('node/'.$node->field_subcats[0]['nid'], NULL, NULL, NULL);
 } else {

 ?>

<div class="subcat-content">
    <div class="subcat-left">
        <h1><?php print $node->title ?></h1>
        <?php if(!empty($node->field_subcats['0']['view'])): ?>
        <div class="item-category">
            <ul>            
            	<?php foreach($node->field_subcats as $sub): ?>
                <?php $cat = node_load($sub['nid']); ?>
                <li><a href="<?php print url('node/'.$cat->nid) ?>" id="#subcat-<?php print $cat->nid ?>"><?php print $cat->title ?></a></li>
                <?php endforeach ?>
            </ul>
        </div><!--/item-category-->
        <?php endif ?>
        <?php if(!empty($node->field_subcats['0']['view'])): $i=0; ?>
		<?php foreach($node->field_subcats as $sub): ?>
		<?php $cat = node_load($sub['nid']); ?>
			<div class="item-pic-<?php print $cat->nid ?>" class="item-details <?php if($i==0) print 'active' ?>">
				<?php print $cat->field_imagesc[0]['view'] ?>
			</div><!--/item-pic-->
		<?php $i++; endforeach ?>
		<?php endif ?>
	</div><!--/subcat-left-->
	<?php if(!empty($node->field_subcats['0']['view'])): $i=0; ?>
    <?php foreach($node->field_subcats as $sub): ?>
    <?php $cat = node_load($sub['nid']); ?>
    <div id="subcat-<?php print $cat->nid ?>" class="subcat-details <?php if($i==0) print 'active' ?>">
        <h5><a href="<?php print url('node/'.$cat->nid) ?>"><?php print $cat->title ?></a> </h5>
        <?php print $cat->body ?>
       <!-- <p><a href="<?php //print url('node/'.$cat->nid) ?>">View Available Inventory.</a></p>-->
    </div><!--/subcat-details-->
    <?php $i++; endforeach ?>
    <?php endif ?>
</div><!--/subcat-content-->
<?php } ?>

Open in new window


Any thoughts?
0
Comment
Question by:iceman19330
2 Comments
 
LVL 12

Accepted Solution

by:
junipllc earned 500 total points
ID: 35172481
What are your display settings for that particular field (as specified in the content type definition, near Manage Fields -- Display Fields, I think it's called)? If you have them set as hidden, the "view" variable may not work.

Typically, I do something like this:

<img src="<?php print $cat->field_imagesc[0]['filepath'] ?>" alt="alt text here" />

Open in new window


or if I need to imagecache it, I use something like this:

$image_alt_text = "ALT TEXT HERE";
$field_imagesc_path = $node->field_imagesc['0']['filepath'];
$field_imagesc_code = theme('imagecache', 'PRESET_NAME', $field_imagesc_path, $image_alt_text, $image_alt_text);
echo $field_imagesc_code;

Open in new window


It looks like nothing is being output at all, but you are getting the node data (e.g. the item pic number). Do you have the development module installed? If you do, you could easily look at the data structure of the node to see how it's being populated by doing a drupal set message on the $cat... which in shorthand is this:

dsm($cat);

...place that right around where you want the picture to be displayed, then reload the page twice. If devel is installed then you should have a nice formatted clickable data structure show up in your messages area. That way you can be sure you have the exact variable you need.

I hope this helps!

Mike
0
 

Author Comment

by:iceman19330
ID: 35172838
Awesome used the img code provided and that worked.  Did tweak the Display fields, but it wasnt set to hidden, it also wasnt set as an image.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Content Policy within SBS 2003 1 31
spoofed email in office 365 3 33
Drupal drupal_get_form() Array Elements 3 66
Customizing themes 14 47
Read about how to approach blogging and about ways to do it right. Stand out from the crowd and let your knowledge be consumed by a large audience. This article aims to explain how your blog should look like,  the most important things to do while b…
Read about how to choose the best possible content marketing agency to suit your needs. Content marketing has become an integral part of running a successful tech business, so it is wise to be informed.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now