Solved

tpl issue with getting an image to show

Posted on 2011-03-19
2
403 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this article, we will look at our content management system as a whole, to get an idea of how we will start to manage these content items.
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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