You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Nathan Quirynen <na...@pensionarchitects.be> on 2016/02/17 17:18:33 UTC
[5.4] Get asset from code
Hi,
in the progress of adapting to 5.4 I'm now moving my assets to the
recomended location " src/main/resources/META-INF/assets/[path to asset]".
In a page or component class I import them using: @Import(stylesheet = {
"[path to asset]" })
In a template I access assets by using: ${asset:[path to asset]}
But how can I get the asset in code? Sometimes the asset is "dynamic"
(based on other parameters).
I thought I'd use one of the methods of AssetSource, but I'm not sure
how to use it as I always get the error that Tapestry can't find the asset.
Nathan
Re: [5.4] Get asset from code
Posted by Nathan Quirynen <na...@pensionarchitects.be>.
Ok thanks guys. Didn't know I had to add "META-INF/assets/" to the path.
I also found that in a template I can also use the following to have a
"dynamic built" path to the asset:
${asset:/}${pathToAsset}
public String getPathToAsset() {
return "images/image-42.png";
}
<ma...@pensionarchitects.be>
On 18/02/16 02:50, JumpStart wrote:
> For example:
>
>
> @Inject
> private AssetSource assetSource;
>
> public String getImageURL() {
> return assetSource.getClasspathAsset("/META-INF/assets/images/image-42.png", currentLocale).toClientURL().toString();
> }
>
> Geoff
>
>> On 18 Feb 2016, at 3:18 am, Thiago H de Paula Figueiredo <th...@gmail.com> wrote:
>>
>> On Wed, 17 Feb 2016 14:18:33 -0200, Nathan Quirynen <na...@pensionarchitects.be> wrote:
>>
>>> Hi,
>> Hi!
>>
>>> But how can I get the asset in code? Sometimes the asset is "dynamic"
>>> (based on other parameters).
>>> I thought I'd use one of the methods of AssetSource, but I'm not sure
>>> how to use it as I always get the error that Tapestry can't find the asset.
>> Check the AssetSource service and its methods. http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/services/AssetSource.html
>>
>> --
>> Thiago H. de Paula Figueiredo
>> Tapestry, Java and Hibernate consultant and developer
>> http://machina.com.br
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>
Re: [5.4] Get asset from code
Posted by JumpStart <ge...@gmail.com>.
For example:
@Inject
private AssetSource assetSource;
public String getImageURL() {
return assetSource.getClasspathAsset("/META-INF/assets/images/image-42.png", currentLocale).toClientURL().toString();
}
Geoff
> On 18 Feb 2016, at 3:18 am, Thiago H de Paula Figueiredo <th...@gmail.com> wrote:
>
> On Wed, 17 Feb 2016 14:18:33 -0200, Nathan Quirynen <na...@pensionarchitects.be> wrote:
>
>> Hi,
>
> Hi!
>
>> But how can I get the asset in code? Sometimes the asset is "dynamic"
>> (based on other parameters).
>> I thought I'd use one of the methods of AssetSource, but I'm not sure
>> how to use it as I always get the error that Tapestry can't find the asset.
>
> Check the AssetSource service and its methods. http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/services/AssetSource.html
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
Re: [5.4] Get asset from code
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 17 Feb 2016 14:18:33 -0200, Nathan Quirynen
<na...@pensionarchitects.be> wrote:
> Hi,
Hi!
> But how can I get the asset in code? Sometimes the asset is "dynamic"
> (based on other parameters).
> I thought I'd use one of the methods of AssetSource, but I'm not sure
> how to use it as I always get the error that Tapestry can't find the
> asset.
Check the AssetSource service and its methods.
http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/services/AssetSource.html
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org