0

I am using Preprocessed Text Templates (.tt) . How can I pass object to another included Preprocessed Text Template? I checked the documentation but didn't find any sample to do that.

Thanks

MZimmerman6
  • 8,445
  • 10
  • 40
  • 70
Kinjal P
  • 19
  • 1
  • 5
  • May I please know why downvote ? Stackoverflow is not right place to ask such questions ? – Kinjal P Aug 20 '13 at 21:53
  • Your question is very short, that is usually considered low quality. Some code to indicate what object to pass and how that other template is included might have helped. Also your comment about XSD below indicates a far wider issue. – H H Aug 20 '13 at 22:15

1 Answers1

0

If you look at the generated code from your preprocessed template, you'll see that it is just a partial class. A great way to pass in data is simply to add another partial of the class, and provide a member and Getter/Setter pair for it. If you then include some further code in that preprocessed template, it will contribute to the same class, so your added member will still be available. If on the other hand, your included code is just class feature clocks (<#+ #>), then you'll likely be defining methods that you can call, in which case you can simply add your data to pass as an extra parameter to those methods.

GarethJ
  • 6,496
  • 32
  • 42
  • I have very complicated xml documents (more than 1000 lines and not following a uniform data elements) with lot of hardcoded values and some values added from object that I pass . It looks like T4 Text templates are not good way to handle it . Do you think anything similar to ruby erb templates in .NET ? https://github.com/projectcypress/health-data-standards/blob/master/templates/cat1/show.cat1.erb . The way it easily includes templates and passes objects if you see at bottom . – Kinjal P Aug 20 '13 at 22:11
  • Are you generating this XML or is it the parameter data for your template to generate something else? – GarethJ Aug 22 '13 at 18:53