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 3285862
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:18:52+00:00 2026-05-17T20:18:52+00:00

I have a template fragment that looks like this: <#+ if (length == 0)

  • 0

I have a template fragment that looks like this:

<#+
if (length == "0") 
#>  return record.Substring(offset);
<#+
else 
#>  return record.Substring(offset, <#= length #>);

When length != “0” it works fine, but when it is “0” it emits the record.Substring(offset); code ok but is then followed by the text “0);” (without the double-quotes) on the next line. It looks like it is emitting the fragment “<#= length #>);” from the else block. I don’t understand why?

  • 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-05-17T20:18:53+00:00Added an answer on May 17, 2026 at 8:18 pm

    You should always use brackets in T4.

    return record.Substring(offset, <#= length #>);
    

    translates to something like

    Write("return record.Substring(offset, ");
    Write(length);
    Write(");");
    

    This is why “else” outputs only the first part.

    Your code should be like this:

    <#+ if (length == "0") { #>
      return record.Substring(offset);
    <#+ } else { #>
      return record.Substring(offset, <#= length #>);
    <#+ } #>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have template that looks like this: 100 template<size_t A0, size_t A1, size_t A2,
I have a template class in C++ that looks like this: template <typename T,
I have template codes with nested curly braces like this: {code{attributes}} I want both
I am hosting SpiderMonkey in a current project and would like to have template
I have a template member function with this signature: template<typename T> void sync(void (*work)(T*),
I have a template class that I serialize (call it C), for which I
I have the following code fragment: template <class T> struct ServicePtr { std::shared_ptr<T> service;
I have this XML fragment: <svrl:successful-report test=. location=/*[local-name()='ClinicalDocument']/*[local-name()='component']/*[local-name()='structuredBody']/*[local-name()='component'][1]/*[local-name()='section']> I want to get the value
I have a template tag that includes a template: def WidgeLoaderNode(IncludeNode): def __init__(tpl, scopes=None):
I have a reusable HTML fragment that I use to list items. So 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.