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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:38:07+00:00 2026-05-14T02:38:07+00:00

I am developing an iPhone application and I use HTML to display formatted text.

  • 0

I am developing an iPhone application and I use HTML to display formatted text.

I often display the same webpage, but with a different content. I would like to use a template HTML file, and then fill it with my different values.

I wonder if Objective-C has a template system similar to ERB in Ruby.

That would allow to do things like

Template:

<HTML>
  <HEAD>
  </HEAD>
  <BODY>
    <H1>{{{title}}}</H1>
    <P>{{{content}}}</P>
  </BODY>
</HTML>

Objective-C (or what it may be in an ideal world)

Template* template = [[Template alloc] initWithFile:@"my_template.tpl"];
[template fillMarker:@"title" withContent:@"My Title"];
[template fillMarker:@"content" withContent:@"My text here"];
[template process];
NSString* result = [template result];
[template release];

And the result string would contain:

<HTML>
  <HEAD>
  </HEAD>
  <BODY>
    <H1>My Title</H1>
    <P>My text here</P>
  </BODY>
</HTML>

The above example could be achieved with some text replacement, but that would be a pain to maintain.
I would also need something like loops inside templates. For instance, if I have multiple items to display, I would like to generate multiple divs.

Thanks for reading 🙂

  • 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-14T02:38:08+00:00Added an answer on May 14, 2026 at 2:38 am

    Have you considered using as template:

    <HTML>
      <HEAD>
      </HEAD>
      <BODY>
        <H1>%@</H1>
        <P>%@</P>
      </BODY>
    </HTML>
    

    And then:

    // just to get file name right
    NSString* fn = 
        [NSString stringWithFormat:@"%@/my_template.tpl", 
                  [[ NSBundle mainBundle ] resourcePath ]];
    // template
    NSError *error;
    NSString* template = 
        [NSString stringWithContentsOfFile:fn 
                  encoding:NSUTF8StringEncoding error:&error];
    // result
    NSString* result = 
        [NSString stringWithFormat:template, 
                  @"MyTitle", 
                  @"MyText"];
    

    I think it’s pretty much what you want.

    Of course you’ll have to add your template files as resources in the project.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am developing a iphone application in a view-based project,(not navigation) however i would
I'm developing an iPhone application that makes heavy use of Core Data, primarily for
I'm developing an iPhone application. I use a NSDictionary to store city's names as
I'm developing an iPhone application which uses a TableView to display XML data. The
I am developing iPhone application and In that application I've one TableViewController , and
I am developing an iPhone application that persists data to a SQLite3 database. For
Coming up towards the end of developing an iPhone application and I'm wondering just
I am developing an iPhone application which is completely based on web data. If
i'm developing an iPhone application and i'm implementing the navigation among views with the
Fellow stackers, I am developing the interface for my iPhone application and I'm in

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.