nvelocity


NVelocity — #parse with embedded resources


I'm generating emails based off embedded NVelocity templates and would like to do something with dynamically included sections. So my embedded resources are something like this:
DigestMail.vm
_Document.vm
_ActionItem.vm
_Event.vm
My email routine will get a list of objects and will pass each of these along with the proper view to DigestMail.vm:
public struct ItemAndView
{
public string View;
public object Item;
}
private void GenerateWeeklyEmail(INewItems[] newestItems)
{
IList<ItemAndView> itemAndViews = new List<ItemAndView>();
foreach (var item in newestItems)
{
itemAndViews.Add(new ItemAndView
{
View = string.Format("MyAssembly.MailTemplates._{0}.vm", item.GetType().Name),
Item = item
});
}
var context = new Dictionary<string, object>();
context["Recipient"] = _user;
context["Items"] = itemAndViews;
string mailBody = _templater.Merge("MyAssembly.MailTemplates.DigestMail.vm", context);
}
And in my DigestMail.vm template I've got something like this:
#foreach($Item in $Items)
====================================================================
#parse($Item.viewname)
#end
But it's unable to #parse when given the path to an embedded resource like this. Is there any way I can tell it to parse each of these embedded templates?
I would do a helper method and rendered InPlace the view stored in resource and returned a string that will be displayed. Something like in this topic here
Template in monorail ViewComponent
Hey Jake, is .viewname a property? I'm not seeing you setting it in your code, how about you use the following:
#foreach($Item in $Items)
====================================================================
$Item.viewname
#end
I don't know why you're parsing the $Item.viename rather than just using the above? I'm suggesting this as I've just never needed to parse anything!
Please refer to this post where we've discussed the generation of templates.
Hope this helps!

Related Links

NVelocity where string value is null
How can I enable logging in NVelocity?
Is unparsed content supported in nVelocity
Does Razor needs MVC3 or can I use it only with .NET?
Why does adding two values in nVelocity always returns zero?
In an NVelocity template how do you test for the existence of a property
NVelocity — #parse with embedded resources
Does NVelocity no longer support string templates?
How can you get NVelocity to initialize correctly?

Categories

HOME
spring
winapi
scipy
cpu-architecture
d
otrs
formal-verification
tomcat7
zend-framework2
is-empty
hyperledger-fabric
criteria
powershell-v3.0
flexbox
cakephp-2.9
wordpress-theming
wysiwyg
dlib
android-toolbar
yeoman-generator
saiku
internet-explorer-8
esql
nsmenuitem
rworldmap
philips-hue
dpi
thinking-sphinx
devforce
vegan
service-locator
honeysql
shibboleth
s3cmd
android-maps-v2
service-fabric-stateful
spring-bean
asmx
rdw
timesten
number-theory
sgmlreader
seamless-immutable
rollback
cgcontext
polar-coordinates
laravel-query-builder
objloader
mix
git-annex
uiprogressview
nofollow
qregexp
squirrel
asp.net-mvc-partialview
yoothemes
galaxy
test-class
windowlistener
team-build
castle-windsor-3
on-duplicate-key
graphical-logo
scrollspy
searchkick
viewflipper
qtestlib
fragment-tab-host
author
proxies
voldemort
broadcasting
convex-polygon
goinstant
astyanax
multiple-conditions
mailcore
fileconveyor
returnurl
xgettext
parameterization
emacs23
newsstand-kit
testunit
smooth
squeel
symbol-server
file-encodings
swfloader
openwysiwyg
hmacsha1
msf
divx

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App