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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:43:14+00:00 2026-05-30T03:43:14+00:00

My function parses through text, grabs parts and generates text only email format. But

  • 0

My function parses through text, grabs parts and generates text only email format. But it also needs to generate html format.

The brain-dead way would be to use if … else … and add additional html tags around each paragraph or element. But it will violate DRY (don’t repeat yourself) rule.

Is there an elegant way to solve this problem?

  • 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-30T03:43:16+00:00Added an answer on May 30, 2026 at 3:43 am

    As @Pointy said, you should look into templates. jQuery templates, while in beta, are good enough – although there are lots of alternatives for good javascript templates.

    In your case, you would do something like:

    $.template("textTemplate", "Hi ${name}!\n\nWelcome as a member!");
    $.template("htmlTemplate", "<h1>Hi ${name}!</h1><p>Welcome as a member!</p>");
    

    And then use them like this:

    var emailText = $.tmpl("textTemplate", data);
    
    // Show the html
    $.tmpl("htmlTemplate", data).appendTo("#container");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a function in PHP that calls a webservice and parses through
I currently have a function that grabs the browser windows uri, parses out the
A library function parses a file and returns an object. If a parser encounters
Python's urlparse function parses an url into six components (scheme, netloc, path and others
I have a function which parses one string into two strings. In C# I
I have a recursion function that parses an object/array with a global variable. If
I need to build a function which parses the domain from a URL. So,
I have a function, parseQuery, that parses a SQL query into an abstract representation
I'm using simplexml() function to parse through RSS feed, while i can access $var->title
I'm trying to read through an xml feed I'm getting, but I can't access

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.