Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass object to template #58

Closed
Starina123 opened this issue Jul 27, 2019 · 4 comments
Closed

Pass object to template #58

Starina123 opened this issue Jul 27, 2019 · 4 comments

Comments

@Starina123
Copy link

Are there any examples of using T4?

I want to pass an object from my application to a template.

Tell me, please, how can I do this?

@Prinsn
Copy link

Prinsn commented Jul 31, 2019

Is this in any way different from how you'd use the classic t4?

You should be able to instantiate and write code in a t4 template.

@mhutch
Copy link
Member

mhutch commented Aug 2, 2019

Are you hosting the engine or using preprocessed templates?

@Starina123
Copy link
Author

I tried to use hosting the engine, but i have little experience.

@mhutch
Copy link
Member

mhutch commented Aug 5, 2019

I would recommend using a session:

var session = generator.GetOrCreateSession ();
session["MyParam"] = paramVal;

If your template is set to be host specific, then parameters declared using a parameter directive will automatically access values from the session.

<#@ template hostspecific="true" #>
<#@ parameter name='MyParam' #>
MyParam value is <#=MyParam#>

@mhutch mhutch closed this as completed Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants