Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8724953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:55:55+00:00 2026-06-13T07:55:55+00:00

I use T4 and Preprocessed Template to generate some codes. So When I add

  • 0

I use T4 and Preprocessed Template to generate some codes. So When I add all of the templates directly in .tt file every things is OK like the following:

<#@ template language="C#" #>
<html><body>
<h1>Sales for Previous Month</h2>
<table>
    <# for (int i = 1; i <= 10; i++)
       { #>
         <tr><td>Test name <#= i #> </td>
             <td>Test value <#= i * i #> </td> </tr>
    <# } #>
 </table>
This report is Company Confidential.
</body></html>

But I need to grouped codes in some methods and call methods in transformText() Method:

MyTemplate.tt file is like the following:

<#@ template language="C#" #>
<#+ 

    private string header(){
#>
<html><body>
<h1>Sales for Previous Month</h2>

<#+ 
    return this.GenerationEnvironment.ToString();
}


private string body() {
#>
    <table>
    <#+ for (int i = 1; i <= 10; i++) { #>

     <tr><td>Test name <#= i #> </td>
         <td>Test value <#= i * i #> </td> </tr>
    <#+ } #>
 </table>
<#+ 
    return this.GenerationEnvironment.ToString();
}


private string footer(){
#>
    This report is Company Confidential ..
</body></html>
<#+ 
    return this.GenerationEnvironment.ToString();
}
#>

And related MyTemplate.cs file is like the following:

// .... 

public virtual string TransformText()
    {
        return this.GenerationEnvironment.ToString();
    }
// .... 

So I call the methods in TransformText() method like this:

// .... 

 public virtual string TransformText()
    {
        header();
        body();
        footer();
        return this.GenerationEnvironment.ToString();
    }
// .... 

So every thing is OK yet, but if I change any thing in .tt file and Save it, the .cs file regenerated again and TransformText() Method return to first implementation (without any calling)?

So how can I use some methods and generate codes in Preprocessed Template? What is your suggestion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:55:56+00:00Added an answer on June 13, 2026 at 7:55 am

    Would this work?

    <#@ template language="C#" #>
    <#
        header ();
        body ();
        foooter ();
    #>
    <#+ ... the rest ... #>
    

    PS. Not sure why you call inside header, body and footer

    return this.GenerationEnvironment.ToString();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know what the command line option is to generate a preprocessed file
I wrote some code to generate a boost::mpl::vector to use as a lookup table
If I use the -E flag when compiling, I get the pre-processed output. Some
use C#,want to upload excel file on google doc. bellow syntax use to upload
How can I switch to a different theme template file for any node that
Is it possible to use a non-type constant template parameter in a preprocessor directive?
I create variables in my preprocess page template function hook_theme_preprocess_page(&$vars) { $vars['myvariable'] = some
I saw the following question: How to generate a newline in a cpp macro?
We have a C++ template library that has some features that depend on zlib,
Often I could use some tools to statically analyze my code in order to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.