How to reuse MVEL templates with @include or @includeNamed?

548 views
Skip to first unread message

Bogdan Sulima

unread,
Jan 19, 2011, 1:56:54 PM1/19/11
to Google Sitebricks
Hello,

how can i reuse MVEL templates by including them with @include tag?

If i have both templates A.mvel and B.mvel in directory webapp/html
and try to include B in A, neither of calls works @include('B.mvel')
and @Include('html/B.mvel').

I am getting following error messages
org.mvel2.templates.TemplateError: cannot include template './
AdList.mvel': file not found. and org.mvel2.templates.TemplateError:
cannot include template './html/AdList.mvel': file not found.

Any ideas how can i use @include?

Dhanji R. Prasanna

unread,
Jan 20, 2011, 1:34:05 AM1/20/11
to google-s...@googlegroups.com
This is a bit tricky. We recommend using embedding and the Bricks templating system for this. But if you have an urgent need we can work through it.

Dhanji.

Bogdan Sulima

unread,
Jan 21, 2011, 4:52:08 AM1/21/11
to google-s...@googlegroups.com
I have tried Bricks templating. 
I have faced some scoping problems with nested Repeat tags and some HTML tag removal due to JSoup parser so i decided to use plain MVEL.

Currently i duplicate a lot of code in my templates so it would be really great to have a possibility to use @include.

Best regards

Bogdan.

Dhanji R. Prasanna

unread,
Jan 21, 2011, 7:32:55 PM1/21/11
to google-s...@googlegroups.com
OK let me think about it and make a patch. In the meantime can you file a bug for the problems with bricks templates? I would like to fix those too!

Thanks,
Dhanji.

John Patterson

unread,
Jan 22, 2011, 1:22:53 AM1/22/11
to google-s...@googlegroups.com
On 22/01/2011 07:32, Dhanji R. Prasanna wrote:
OK let me think about it and make a patch. In the meantime can you file a bug for the problems with bricks templates? I would like to fix those too!

Thanks,
Dhanji.

On Fri, Jan 21, 2011 at 8:52 PM, Bogdan Sulima <bogdan...@gmail.com> wrote:
I have tried Bricks templating. 
I have faced some scoping problems with nested Repeat tags and some HTML tag removal due to JSoup parser so i decided to use plain MVEL.

Currently i duplicate a lot of code in my templates so it would be really great to have a possibility to use @include.


I've also had to switch to mvel templates because of problems such as not being able to use mvel in repeat elements.

e.g.

@Repeat
<tag attribute="${never_evaluated}"/>

or

<input ${cannot_parse_this}/>

so for now, mvel includes would be a great start.

Bogdan Sulima

unread,
Jan 22, 2011, 6:23:46 AM1/22/11
to google-s...@googlegroups.com
Unfortunately i have deleted that code. At that time i was not sure if i will use sitebricks for further development so i did not file the issues.

I think i was not able to access object methods of the outer loop from the inner one. NoSuchMethod exception was thrown.

Also all javascript tags following HTML tag have been removed and STYLES block from the HEAD was also removed (despite the resolved bug).

Best regards,

Bogdan.

John Patterson

unread,
Jan 22, 2011, 6:49:51 AM1/22/11
to google-sitebricks
On 22 January 2011 18:23, Bogdan Sulima <bogdan...@gmail.com> wrote:
the outer loop from the inner one. NoSuchMethod exception was thrown.

You must use ${__page.method()} from within a repeat brick.  I started some work several weeks ago to add scoped context which I hope to submit soon.
 
Also all javascript tags following HTML tag have been removed and STYLES block from the HEAD was also removed (despite the resolved bug).

Did you use @Required on the styles?

This "header inclusion" working for me but unfortunately the order of the header elements is mixed up so I needed to put <style> tags in the body instead.

Dhanji R. Prasanna

unread,
Jan 22, 2011, 7:24:03 PM1/22/11
to google-s...@googlegroups.com
Btw, this should already be fixed in trunk.

Thanks,
Dhanji.

John Patterson

unread,
Jan 23, 2011, 1:26:15 AM1/23/11
to google-s...@googlegroups.com
I looked into @include a little and there seems to be a problem with
MVEL always looking for include files relative to the current
directory. It seems impossible to resolve these files from a different
location.

CompiledIncludeNode.readInFile(File) also does some pushing and popping
of directories to a stack that seems to be a no-op? Also, a byte buffer
of 10 bytes seems to be a little stingy!

I have mvel 2.0.16

John Patterson

unread,
Jan 23, 2011, 1:41:59 AM1/23/11
to google-s...@googlegroups.com
Just to add a little context to the original exception:

org.mvel2.templates.TemplateError: cannot include template '.\include.mvel': file not found.
at org.mvel2.templates.res.CompiledIncludeNode.readInFile(CompiledIncludeNode.java:141)
at org.mvel2.templates.res.CompiledIncludeNode.readFile(CompiledIncludeNode.java:88)
at org.mvel2.templates.res.CompiledIncludeNode.eval(CompiledIncludeNode.java:78)
at org.mvel2.templates.res.TextNode.eval(TextNode.java:46)

Message has been deleted

Dhanji R. Prasanna

unread,
Feb 3, 2011, 1:12:55 AM2/3/11
to google-s...@googlegroups.com, Mike Brock
adding mike who might be able to shed some light.

On Thu, Feb 3, 2011 at 10:20 AM, Pete <peter....@gmail.com> wrote:
What special setup do I need to do to use MVEL orb tags in my site? I too wanted to use @include to add headers and footers, but I've been unable to use any tags with @ instead of $. I feel like there must be some setup I'm missing, but I don't see anything special in MvelTemplateExample.java in the acceptance tests. If I include something like @{message} it just gets rendered out to the browser.

I'm using sitemesh for my layout, but I'd like to stick to one tool for all layout. Is there a better way to create "master pages"?

John Patterson

unread,
Feb 3, 2011, 1:57:58 AM2/3/11
to google-s...@googlegroups.com
On 3 February 2011 06:20, Pete <peter....@gmail.com> wrote:
What special setup do I need to do to use MVEL orb tags in my site? I too wanted to use @include to add headers and footers, but I've been unable to use any tags with @ instead of $. I feel like there must be some setup I'm missing, but I don't see anything special in MvelTemplateExample.java in the acceptance tests. If I include something like @{message} it just gets rendered out to the browser.

I can confirm that .mvel templates work for me without any special set up using the latest source.  But it looks like mvel @include orbs are hard coded to look for files relative to the current working directory which is not very useful.

Dhanji R. Prasanna

unread,
Feb 3, 2011, 2:04:39 AM2/3/11
to google-s...@googlegroups.com, Mike Brock
[+brockm]

Please reply-all...

Pete

unread,
Feb 3, 2011, 1:43:08 PM2/3/11
to google-s...@googlegroups.com, Mike Brock
Hey, sorry for deleting my original post. I realized I was using $ and @ incorrectly and wanted to remove any erroneous post and maybe replace it. I forgot that I actually sent an email.

My only knock against using Sitemesh templates, is that I can't use sitebricks tags in my template pages eaisly. How are people handling layout templating?

Dhanji R. Prasanna

unread,
Feb 3, 2011, 5:36:01 PM2/3/11
to google-s...@googlegroups.com, Mike Brock
Hmm, we can develop a Sitemesh integration pretty easily. Or just do something that works for us now.

Most Sitebricks apps I write are RIAs so they generally only have one page and lots of fragments or JSON loaded via ajax.

sathis...@wavecrest.gi

unread,
Aug 8, 2014, 4:42:18 AM8/8/14
to google-s...@googlegroups.com, bro...@gmail.com
Can anyone helps me to include one mvel into another mvel , I am getting the File not found exception even though file is present in the same directory,

org.mvel2.templates.TemplateError: cannot include template '.\Footer.txt': file not found.
at org.mvel2.templates.res.CompiledIncludeNode.readInFile(CompiledIncludeNode.java:115) ~[mvel2-2.1.3.Final.jar:?]
at org.mvel2.templates.res.CompiledIncludeNode.readFile(CompiledIncludeNode.java:78) ~[mvel2-2.1.3.Final.jar:?]

My Code is
Dear @{FIRST_NAME},
Hello How are you??
@include('./Footer.txt')

where Footer.txt contains a sample data

Thanks
Satish

but its throwing the exception as file not found

Reply all
Reply to author
Forward
0 new messages