If anyone has got this working with contemplate please can they put together some documentation on how to do it along with some examples - they would be greatly appreciated! I've been trying to get this working and i can get img scr's printed in the code but don't get any sizes on them at all - so they wont appear on the page.

Cheers

Lucy

CommentFileSizeAuthor
#10 screenshot_4.gif29.45 KBstanbroughl
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stanbroughl’s picture

this is what i get printed in my source code:

<div class="field field-type-image field-field-hazard-image-0">
  <h3 class="field-label">image</h3>
  <div class="field-items">
          <div class="field-item"><img src="/files/imagecache/hazardimagery/1"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/t"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/t"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/9"></div>

          <div class="field-item"><img src="/files/imagecache/hazardimagery/D"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/f"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/i"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/2"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/<"></div>
      </div>
</div>

for this contemplate coding - with a resize of 300x300 set on it:

<div class="field field-type-image field-field-hazard-image-0">
  <h3 class="field-label">image</h3>
  <div class="field-items">
    <?php foreach ((array)$field_hazard_image_0[0] as $item) { ?>
      <div class="field-item"><?php print '<img src="/files/imagecache/hazardimagery/'.$item['filepath']. '">'; ?></div>
    <?php } ?>
  </div>
</div>
stanbroughl’s picture

Version: 4.7.x-1.x-dev » 6.x-2.x-dev

this is what i get printed in my source code:

<div class="field field-type-image field-field-hazard-image-0">
  <h3 class="field-label">image</h3>
  <div class="field-items">
          <div class="field-item"><img src="/files/imagecache/hazardimagery/1"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/t"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/t"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/9"></div>

          <div class="field-item"><img src="/files/imagecache/hazardimagery/D"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/f"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/i"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/2"></div>
          <div class="field-item"><img src="/files/imagecache/hazardimagery/<"></div>
      </div>
</div>

for this contemplate coding - with a resize of 300x300 set on it:

<div class="field field-type-image field-field-hazard-image-0">
  <h3 class="field-label">image</h3>
  <div class="field-items">
    <?php foreach ((array)$field_hazard_image_0[0] as $item) { ?>
      <div class="field-item"><?php print '<img src="/files/imagecache/hazardimagery/'.$item['filepath']. '">'; ?></div>
    <?php } ?>
  </div>
</div>
dopry’s picture

try
foreach ((array)$field_hazard_image_0 as $delta => $item) { ?>

instead of
foreach ((array)$field_hazard_image_0[0] as $item) { ?>

or just remove the [0] after the variable name.

stanbroughl’s picture

i've tried your suggestion but all i'm getting coming up in the source is this, with no images shown:

<div class="field field-type-image field-field-hazard-image-0">
<h3 class="field-label">image</h3>
<div class="field-items">
<div class="field-item"><img src="/files/imagecache/hazardimagery/1"></div>
<div class="field-item"><img src="/files/imagecache/hazardimagery/t"></div>
<div class="field-item"><img src="/files/imagecache/hazardimagery/t"></div>
<div class="field-item"><img src="/files/imagecache/hazardimagery/9"></div>
<div class="field-item"><img src="/files/imagecache/hazardimagery/D"></div>
<div class="field-item"><img src="/files/imagecache/hazardimagery/f"></div>
<div class="field-item"><img src="/files/imagecache/hazardimagery/i"></div>
<div class="field-item"><img src="/files/imagecache/hazardimagery/2"></div>
<div class="field-item"><img src="/files/imagecache/hazardimagery/%3C"></div>
</div>
</div>

any other suggestions? they would be greatly appreciated!

Cheers

Lucy

dopry’s picture

Can you give me a print_r() of the field?

stanbroughl’s picture

Array
(
[0] => Array
(
[fid] => 93
[title] => inTERRAgate at the EWC3
[alt] => inTERRAgate at the EWC3
[nid] => 93
[filename] => DSC01011.JPG
[filepath] => files/DSC01011.JPG
[filemime] => image/jpeg
[filesize] => 2336605
[view] => Only local images are allowed.

)

)

dopry’s picture

and what exactly is in your template currently?

It seems you are not properly referencing/printing the filepath value.

stanbroughl’s picture

this is what i have in my contemplate template for that image:

image

foreach ((array)$field_hazard_image_0[0] as $item) {
print '<img src="/files/imagecache/hazardimagery/'.$item['filepath']. '">';

}

dopry’s picture

What is the output with the solution tendered in comment #3?

stanbroughl’s picture

FileSize
29.45 KB

i get this for the teaser (the image i'm interested in is this part -

Only local images are allowed.

):

  <div class="node">
        <h2 class="title"><a href="/news/situation-reports/90" title="news test">news test</a></h2>
        <span class="submitted">Submitted by <a href="/user/admin" title="View user profile.">admin</a> on Thu, 10/08/2006 - 10:35.</span>
    <span class="taxonomy"><a href="/news/situation_reports" rel="tag" title="">Situation reports</a></span>

    <div class="content"><table width="100%">
<tbody><tr>
<td>
<div class="news-teaser">
           <div class="field-item"><img src="/files/imagecache/hazardimagery/files/DSC00757_0.JPG"></div>
      </div>
I am a news story, I am a news story, I am a news story, I am a news story, I am a news story, I am a news story, I am a news story, I am a news story, I am a news story, I am a news story, I am a news story, I am a news story, I am a news story, I am a news story, I am a news story, I am a news sto<a href="news/situation-reports/90">...readmore</a>
</td>
</tr>
</tbody></table></div>
    <div class="links">» by <a href="/lucys_biography" title="View admin's biography.">admin</a> – <a href="/comment/reply/90#comment_form" title="Add a new comment to this page.">add new comment</a></div>

  </div>

which doesn't give me an image on the screen - just a tiny dot on each story - regardless of whether they have an image in the field - which i've highlighted on the screenshot

dopry’s picture

It seems like the path is correct..... You may need to fidget with the .htaccess to make it work... I'm not sure that that is currently documented. I know it is necessary for previews.

comment out everything in the .htaccess file in your files directory and see if it is fixed...
I know there are some issues with that... If that works I'll make it a point to add that to the docs... and Give you an alternative .htaccess file you can use that covers the security points covered by that one.

stanbroughl’s picture

i'm developing the site on my local machine (apache2triad: php 4.4.2 and MySQL 5.0.18) so haven't changed any of the settings from the default .htaccess file yet - what do i need to change here?:

#
# Apache/PHP/Drupal settings:
#

# Protect files and directories from prying eyes.
<FilesMatch "(\.(engine|inc|install|module|sh|.*sql|theme|tpl(\.php)?|xtmpl)|code-style\.pl|Entries.*|Repository|Root)$">
  Order deny,allow
  Deny from all
</FilesMatch>

# Set some options.
Options -Indexes
Options +FollowSymLinks

# Customized error messages.
ErrorDocument 404 /index.php

# Set the default handler.
DirectoryIndex index.php

# Override PHP settings. More in sites/default/settings.php
# but the following cannot be changed at runtime.

# PHP 4, Apache 1
<IfModule mod_php4.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
</IfModule>

# PHP 4, Apache 2
<IfModule sapi_apache2.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
</IfModule>

# PHP 5, Apache 1 and 2
<IfModule mod_php5.c>
  php_value magic_quotes_gpc                0
  php_value register_globals                0
  php_value session.auto_start              0
</IfModule>

# Reduce the time dynamically generated pages are cache-able.
<IfModule mod_expires.c>
  ExpiresByType text/html A1
</IfModule>

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # If your site can be accessed both with and without the prefix www.
  # you can use one of the following settings to force user to use only one option:
  #
  # If you want the site to be accessed WITH the www. only, adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
  # RewriteRule .* http://www.example.com/ [L,R=301]
  #
  # If you want the site to be accessed only WITHOUT the www. , adapt and uncomment the following:
  # RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
  # RewriteRule .* http://example.com/ [L,R=301]


  # Modify the RewriteBase if you are using Drupal in a subdirectory and
  # the rewrite rules are not working properly.
  #RewriteBase /drupal

  # Rewrite old-style URLs of the form 'node.php?id=x'.
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteCond %{QUERY_STRING} ^id=([^&]+)$
  #RewriteRule node.php index.php?q=node/view/%1 [L]

  # Rewrite old-style URLs of the form 'module.php?mod=x'.
  #RewriteCond %{REQUEST_FILENAME} !-f
  #RewriteCond %{REQUEST_FILENAME} !-d
  #RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
  #RewriteRule module.php index.php?q=%1 [L]

  # Rewrite current-style URLs of the form 'index.php?q=x'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

# $Id: .htaccess,v 1.73 2006/04/14 09:08:26 killes Exp $
scroogie’s picture

No, hes talking about the .htaccess in your file path, per default '/files'. There should be no more than 4 lines in it.

scroogie’s picture

By the way, I use imagecache with contemplate and it works flawlessly.

<?php foreach ((array)$field_foto as $item) { ?>
      <div class="field-item">
<img src="/files/imagecache/cachename/<?php print $item['filepath'] ?>" alt="<?php print $item['alt'] ?>" title="<?php print $item['title'] ?>" />
</div>
    <?php } ?>
stanbroughl’s picture

ok it a go and see what happens - i'm stripping back my site because of some problems i had with my database so hopefully they will fix it.

Can you give me a print out of what should be in that section of the files .htaccess as i'm not sure if i've added the options in the right place now:


SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options None

//RewriteEngine off
+FollowSymlinks

scroogie’s picture

This is what the .htaccess should look like:

SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options +FollowSymlinks
<IfModule mod_rewrite.c>
   RewriteEngine on
</IfModule>
catch’s picture

I got it working (with scale, nothing with crop unfortunately).

Using this contemplate code:

<div id="news-photo">
<a href="<?php print $path ?>">
<?php foreach ((array)$field_photo as $item) { ?>
<?php print '<img src="/files/imagecache/thumb/'.$item['filepath']. '">'; ?>
<?php } ?>
</a>
</div>

Which also turns every image into a link to the article.

and this .htaccess in the files directory.

#SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options +FollowSymlinks
#
#RewriteEngine on
#

Had to make the imagecache/thumb/files directory structure under my files directory manually.

php4 gd2, image magick.

It looks and works great in firefox.

In internet explorer I have two issues:

1. the thumbnails link to my index page instead of the article.
2. all the articles without images give me broken images.

any help much appreciated fixing those. Good progress though and thanks for all the posts on this issue - been a big help.

scroogie’s picture

About the broken images, I thought the array wouldnt be populated if the field is empty, but if it gets you could do an empty() check like this:

 foreach ((array)$field_foto as $item) { 
      if (empty($item['filepath'])) continue;
Only local images are allowed. print $item['filepath'] " alt=" print $item['alt'] " title=" print $item['title'] " />

}

scroogie’s picture

Sorry, forgot to wrap it in code tags and cannot edit my first comment. Here it is. Memo to self: use preview ;)

<?php foreach ((array)$field_foto as $item) { 
   if (empty($item['filepath'])) continue;
?>
<div class="field-item">
<a href="node/<?php print $nid ?>">
<img src="/files/imagecache/cachename/<?php print $item['filepath'] ?>" alt="<?php print $item['alt'] ?>" title="<?php print $item['title'] ?>" />
</a>
</div>
<?php } ?>
catch’s picture

lovely - working great!

dopry’s picture

I committed some new code to imagecache today. Imagecache should now work with non-default file paths.
I also added a convenient theme_imagecache function that can be called like...

theme('imagecache', $ruleset, $image_path);

This should resolve issues with multisites and any non-default file paths. as well as make it a little easier to work with since you guys won't have to construct the imagecache paths anymore.

I'd appreciate people testing the new code in cvs head.

dopry’s picture

Status: Active » Fixed

docs for the new theme function are in the README. plus some details about setting up a ruleset.

stanbroughl’s picture

Cheers! sorry for not replying to all these things this week, i've been out in the middle of switzerland with the worst internet connection ever lol!

i'll have a proper investigate later but it all looks good at the moment - thanks for all your help!

Anonymous’s picture

Status: Fixed » Closed (fixed)