You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by bluejoe2008 <bl...@gmail.com> on 2010/04/25 08:37:47 UTC

how to determine the included template file exists or not?

how to determine the included template file exists or not?  in my .vm page, i want to write such codes as follows:

#set($var=$param("fileName"))
#parse("${var}.inc")

but sometimes the inc file, e.g "hello.inc", does not exist
so i want to find a way to determine if the included file exists
if yes, parse it, otherwise ignore the #parse directive without any exception

can anyone tell me how to do it?

2010-04-25 



bluejoe2008 

Re: Re: how to determine the included template file exists or not?

Posted by Nathan Bubna <nb...@gmail.com>.
I think you can create an IncludeEventHandler that returns null when
the template doesn't exists, which would cause the #parse to be
skipped.

On Sun, Apr 25, 2010 at 12:31 AM, bluejoe2008 <bl...@gmail.com> wrote:
> but hello.inc maybe is a relative path
> and it is difficult for $templateTool to decide
>
> 2010-04-25
>
>
>
> bluejoe2008
>
>
>
> 发件人: Jarkko_Viinamäki-2
> 发送时间: 2010-04-25  15:26:25
> 收件人: user
> 抄送:
> 主题: Re: how to determine the included template file exists or not?
>
> One option is to write a Java class for checking template existence and put
> it in Velocity context as a tool.
> #if( $templateTool.exists("hello.inc") )
>  #parse("hello.inc")
> #end
> bluejoe-2 wrote:
>>
>> how to determine the included template file exists or not?  in my .vm
>> page, i want to write such codes as follows:
>>
>> #set($var=$param("fileName"))
>> #parse("${var}.inc")
>>
> --
> View this message in context: http://old.nabble.com/how-to-determine-the-included-template-file-exists-or-not--tp28354538p28354663.html
> Sent from the Velocity - User mailing list archive at Nabble.com.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: Re: how to determine the included template file exists or not?

Posted by bluejoe2008 <bl...@gmail.com>.
but hello.inc maybe is a relative path
and it is difficult for $templateTool to decide

2010-04-25 



bluejoe2008 



发件人: Jarkko_Viinamäki-2 
发送时间: 2010-04-25  15:26:25 
收件人: user 
抄送: 
主题: Re: how to determine the included template file exists or not? 
 
One option is to write a Java class for checking template existence and put
it in Velocity context as a tool.
#if( $templateTool.exists("hello.inc") )
  #parse("hello.inc")
#end
bluejoe-2 wrote:
> 
> how to determine the included template file exists or not?  in my .vm
> page, i want to write such codes as follows:
> 
> #set($var=$param("fileName"))
> #parse("${var}.inc")
> 
-- 
View this message in context: http://old.nabble.com/how-to-determine-the-included-template-file-exists-or-not--tp28354538p28354663.html
Sent from the Velocity - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org

Re: how to determine the included template file exists or not?

Posted by Jarkko Viinamäki-2 <wy...@sci.fi>.
One option is to write a Java class for checking template existence and put
it in Velocity context as a tool.

#if( $templateTool.exists("hello.inc") )
  #parse("hello.inc")
#end



bluejoe-2 wrote:
> 
> how to determine the included template file exists or not?  in my .vm
> page, i want to write such codes as follows:
> 
> #set($var=$param("fileName"))
> #parse("${var}.inc")
> 

-- 
View this message in context: http://old.nabble.com/how-to-determine-the-included-template-file-exists-or-not--tp28354538p28354663.html
Sent from the Velocity - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org