?
Solved

tpl issue with getting an image to show

Posted on 2011-03-19
2
Medium Priority
?
409 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Accepted Solution

by:
junipllc earned 2000 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for those that are having major problems with users upload files such as pictures to their profile. The solution is simple and has to do with correcting the directory paths. With some experimenting and testing i got it fixed. Note…
There is a massive demand for content on the web right now, and it doesn't look like it's going to stop any time soon. But, if you are running a business blog, it's not just enough to offer your audience lots of content. It needs to be high-quality…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

777 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