This one also got lost -- I assume do to my single-line patch.
Here it is again with docs and tests.
There's two things: first, I added docs for the existing but
undocumented "root" parameter.
Second, I added a way to specify a separate file and url path when
the path and the url space don't match up.
Here was my original, yet a bit verbose, example:
Under Catalyst applications can (or should) be designed to run
in any URL namespace. That is, Catalyst uses PATH_INFO to determine
the action to take so the application can be aliased anywhere (just
like a plain old CGI script):
With Apache:
Alias /myapp /path/to/real/app
Alias /myapp/also /path/to/real/app
So relative paths won't work.
With that you can't easily use the Image plugin because it builds the
src tag based on the filename.
USE Image(
root = '/path/to/real/app'
name = '/images/foo.png'
);
So, it will find the image, but the src will not include /myapp or
/myapp/also.
So with the patch I can specify the file name and the URL
separately:
file_name = '/trainers/' _ item.id _ '.jpg';
image_file = c.path_to( 'root', file_name);
image_url = c.uri_for( file_name );
USE Image( file = "$image_file", name = "$image_url");
(the quotes are needed to stringify)
The other reason is a url /images/logo.png might get dynamically mapped
to different files based on, say, some value in the session. So need a way
to specify the path and url separately.
Index: docsrc/src/Modules/Template/Plugin/Image.tt2
===================================================================
RCS file:
/template-toolkit/Template2/docsrc/src/Modules/Template/Plugin/Image.tt2,v
retrieving revision 1.3
diff -u -B -r1.3 Image.tt2
--- docsrc/src/Modules/Template/Plugin/Image.tt2 2003/03/18 00:14:06
1.3
+++ docsrc/src/Modules/Template/Plugin/Image.tt2 2005/12/24 16:26:59
@@ -24,6 +24,17 @@
[% USE image(name='baz.gif') %]
[% USE Image name='pong.gif' %]
+A "root" parameter can be used to specify the location of the image file:
+
+ [% USE Image(root='/path/to/root', name='images/home.png') %]
+ # image path: /path/to/root/images/home.png
+ # img src: images/home.png
+
+In cases where the image path and image url do not match up, specify the
+file name directly:
+
+ [% USE Image(file='/path/to/home.png', name='/images/home.png') %]
+
You can also provide an alternate name for an Image plugin object.
[% USE img1 = image 'foo.gif' %]
Index: lib/Template/Plugin/Image.pm
===================================================================
RCS file: /template-toolkit/Template2/lib/Template/Plugin/Image.pm,v
retrieving revision 1.15
diff -u -B -r1.15 Image.pm
--- lib/Template/Plugin/Image.pm 2005/11/29 07:37:48 1.15
+++ lib/Template/Plugin/Image.pm 2005/12/24 16:26:59
@@ -85,7 +85,7 @@
$file = File::Spec->catfile($root, $name);
}
else {
- $file = $name;
+ $file = $config->{file} || $name;
}
# Make a note of whether we are using Image::Size or
Index: t/image.t
===================================================================
RCS file: /template-toolkit/Template2/t/image.t,v
retrieving revision 1.3
diff -u -B -r1.3 image.t
--- t/image.t 2003/03/18 00:06:25 1.3
+++ t/image.t 2005/12/24 16:26:59
@@ -34,6 +34,7 @@
file => {
logo => File::Spec->catfile($dir, 'ttdotorg.gif'),
power => File::Spec->catfile($dir, 'tt2power.gif'),
+ lname => 'ttdotorg.gif',
},
};
@@ -84,5 +85,18 @@
tag: <img src="[% file.logo %]" width="110" height="60" />
tag: <img src="[% file.logo %]" width="110" height="60" class="myimage" />
+# test "root"
+-- test --
+[% USE image( root=dir name=file.lname ) -%]
+[% image.tag %]
+-- expect --
+-- process --
+<img src="[% file.lname %]" width="110" height="60" />
+# test separate file and name
+-- test --
+[% USE image( file= file.logo name = "other.jpg" ) -%]
+[% image.tag %]
+-- expect --
+<img src="other.jpg" width="110" height="60" />
--
Bill Moseley
[EMAIL PROTECTED]
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates