Ruby Forum Radiant CMS > conditional display of image

Posted by Mathieu Arnold (Guest)
on 11.10.2007 13:29
(Received via mailing list)
Hi,

I'm attaching some images to some posts on my blog, and as I don't want 
to
have too big images on the home page and on the archive pages, I devised 
the
following code that I put on the first part of my page

<r:unless cond="!request.nil? && Regexp.new(tag.locals.page.slug) =~
request.env['REQUEST_URI']">
!{float:right}<r:attachment_url transform="120" id="10"/>(foo)!
</r:unless>
<r:if cond="!request.nil? && Regexp.new(tag.locals.page.slug) =~
request.env['REQUEST_URI']">
!{float:right}<r:attachment_url transform="200" id="10"/>(foo)!
</r:if>

(the 120 and 200 transforms resize to 120x120 and 200x200)

The strange thing, it that I don't always get a "request" object, and 
I'm
wondering if there could be a better way to do that, the main point 
being "is
the page being displayed is the page I belong too".

Regards,
Posted by Aitor Garay-Romero (Guest)
on 12.10.2007 14:04
(Received via mailing list)
>The strange thing, it that I don't always get a "request" object, and I'm
  >wondering if there could be a better way to do that, the main point 
being
"is
  >the page being displayed is the page I belong too".

   Sorry, i don't quite understand the question.  The code you post, is 
in a
page, snippet or layout?

   /AITOR
Posted by Mathieu Arnold (Guest)
on 12.10.2007 15:27
(Received via mailing list)
+-le 12.10.2007 13:37:30 +0200, Aitor Garay-Romero a dit :
|   >The strange thing, it that I don't always get a "request" object, and I'm
|   >wondering if there could be a better way to do that, the main point being
| "is
|   >the page being displayed is the page I belong too".
| 
|    Sorry, i don't quite understand the question.  The code you post, is in a
| page, snippet or layout?

The code I post is in a page part.
I'm wondering if I could do something like tags.locals.page.id == 
self.id.
And after a few though, I could/should maybe make two parts, one that 
would
show on the page and one that would show in the Archive index.
Posted by Mathieu Arnold (Guest)
on 12.10.2007 15:31
(Received via mailing list)
+-le 12.10.2007 15:26:40 +0200, Mathieu Arnold a dit :
| +-le 12.10.2007 13:37:30 +0200, Aitor Garay-Romero a dit :
||   > The strange thing, it that I don't always get a "request" object, and
||   > I'm wondering if there could be a better way to do that, the main
||   > point being
|| "is
||   > the page being displayed is the page I belong too".
|| 
||    Sorry, i don't quite understand the question.  The code you post, is in
||    a page, snippet or layout?
| 
| The code I post is in a page part.
| I'm wondering if I could do something like tags.locals.page.id == self.id.
| And after a few though, I could/should maybe make two parts, one that would
| show on the page and one that would show in the Archive index.

Hum, maybe I should show what I mean :
http://w.mat.cc/
and
http://w.mat.cc/articles/2007/10/06/a-vif-une-touche-d-humanite/

That is, having a smaller image on the home page so that it does not 
take too
much room.

Regards,
Posted by Daniel Sheppard (Guest)
on 13.10.2007 03:29
(Received via mailing list)
On Fri, 12 Oct 2007 15:26:40 +0200
Mathieu Arnold <mat@mat.cc> wrote:

> I'm wondering if I could do something like tags.locals.page.id ==
> self.id. And after a few though, I could/should maybe make two parts,
> one that would show on the page and one that would show in the
> Archive index.
> 

You should get the request object from tags.globals.page, not
tag.locals.page.

Dan.
Posted by Ben Morrow (benmorrow)
on 27.04.2008 02:08
Mathieu Arnold wrote:
> Hi,
> 
> I'm attaching some images to some posts on my blog, and as I don't want 
> to
> have too big images on the home page and on the archive pages, I devised 
> the
> following code that I put on the first part of my page
> 
> <r:unless cond="!request.nil? && Regexp.new(tag.locals.page.slug) =~
> request.env['REQUEST_URI']">
> !{float:right}<r:attachment_url transform="120" id="10"/>(foo)!
> </r:unless>
> <r:if cond="!request.nil? && Regexp.new(tag.locals.page.slug) =~
> request.env['REQUEST_URI']">
> !{float:right}<r:attachment_url transform="200" id="10"/>(foo)!
> </r:if>
> 
> (the 120 and 200 transforms resize to 120x120 and 200x200)

Is that "transform" something custom or does it ship with the Page 
Attachments plugin?

I see that in the "available tags for page" help, it says:

> <r:attachment:image />
> Renders an image tag for the attachment (assuming it’s an image). 
> The ‘name’ attribute is required on this tag or the parent tag. 
> Any other attributes will be added as HTML attributes to the rendered tag. 
> The optional ‘size’ attribute allows you to show the icon size of the image.

> Usage:
> <r:attachment:image name="file.jpg" [size="icon"]/>

Also, are there other sizes available like "large" and "medium", or is 
"icon" the only one?

Regards,
Ben

Posted by Dominic (Guest)
on 27.04.2008 11:46
(Received via mailing list)
On 27 Apr 2008, at 01:08, Ben Morrow wrote:

>>
>> Usage:
>> <r:attachment:image name="file.jpg" [size="icon"]/>
>
> Also, are there other sizes available like "large" and "medium", or is
> "icon" the only one?


I think you used to have to change a couple of files.

In vendor/page_attachments/app/models/page_attachment.rb you can add
more thumbnail sizes:
:thumbnails => {:icon => '50x50>', :small => '160x160>', :medium =>
'320x320>', :large => '640x640>'},

and also change the admin view to find the right icon thumbnail:
<%= link_to image_tag(attachment.thumbnails.find(:first, :conditions
=> "thumbnail = 'icon'").public_filename, :class => "thumbnail") %>

Specifying a image size seems to expose the size="icon" attribute in
the outputted page though. Is there a patch out there for fixing this?

Dominic
Posted by Ben Morrow (benmorrow)
on 09.05.2008 18:00
Dominic wrote:
> I think you used to have to change a couple of files.
> 
> In vendor/page_attachments/app/models/page_attachment.rb you can add
> more thumbnail sizes:
> :thumbnails => {:icon => '50x50>', :small => '160x160>', :medium =>
> '320x320>', :large => '640x640>'},
> 
> and also change the admin view to find the right icon thumbnail:
> <%= link_to image_tag(attachment.thumbnails.find(:first, :conditions
> => "thumbnail = 'icon'").public_filename, :class => "thumbnail") %>

Just had a chance to try this. It works brilliantly! In the page admin, 
I can simply drag the link from "Attachments" section and add the size I 
want to the end of the file name. Ex:

http://domain.com/image_small.jpg

Since I use Textile, I then add the image tag (!) and float it right 
like so:

!>http://domain.com/image_small.jpg!

Thanks for your help, Dominic!