You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peter Stavrinides <P....@albourne.com> on 2009/01/20 17:06:13 UTC

How to get assets from the classpath

Hi 

Sorry about the trivial question, but I have just spent far to much time trying to figure this out... I am sure I am missing something blindingly simple:

I am trying to contribute an alias and retrieve an image from the classpath, like this:

public static void contributeClasspathAssetAliasManager(
     MappedConfiguration<String, String> configuration){
        configuration.add("webimages", "com/apl/web/static/images/");
    }

In my .tml file I can get at the image like this:
<img src="../assets/webimages/myimage.gif" />

Or if I hardcode the application context like this:
/myapp/assets/webimages/myimage.gif

But I need Tapestry to give me the /myapp/ part... I tried all sorts of things, I assumed I could use ${asset:context:/webimages/myimages.gif}, but that didn't work, any ideas?

Thanks for your help,
Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to get assets from the classpath

Posted by Howard Lewis Ship <hl...@gmail.com>.
${asset:/com/apl/web/static/images/myimage.gif}

The prefixes are just for references from the client side, not for code.

Also, you should incorporate a version number when mapping:

public static void contributeClasspathAssetAliasManager(
    MappedConfiguration<String, String> configuration){
  String version =  . . . ;
   configuration.add(version + "/webimages", "com/apl/web/static/images/");
   }

On Tue, Jan 20, 2009 at 8:06 AM, Peter Stavrinides
<P....@albourne.com> wrote:
> Hi
>
> Sorry about the trivial question, but I have just spent far to much time trying to figure this out... I am sure I am missing something blindingly simple:
>
> I am trying to contribute an alias and retrieve an image from the classpath, like this:
>
> public static void contributeClasspathAssetAliasManager(
>     MappedConfiguration<String, String> configuration){
>        configuration.add("webimages", "com/apl/web/static/images/");
>    }
>
> In my .tml file I can get at the image like this:
> <img src="../assets/webimages/myimage.gif" />
>
> Or if I hardcode the application context like this:
> /myapp/assets/webimages/myimage.gif
>
> But I need Tapestry to give me the /myapp/ part... I tried all sorts of things, I assumed I could use ${asset:context:/webimages/myimages.gif}, but that didn't work, any ideas?
>
> Thanks for your help,
> Peter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org