Storing, maintaining, and using String Templates with PHP

What this thread IS NOT: This thread (or question) has nothing to do with Language Translations whatsoever. So if anyone is trying to post a solution about Language Translations or multi-language user interfaces―simply stop now―since I am not interested.

I am NOT OUT FOR: Any popular Templating Engine, since I already have a HTML templating engine written in PHP.

This thread is all about String Templates. Since I have never dealt with something like this before, I am curious what other people might have to offer. I am looking for something in PHP ONLY. NOT Interested in using third-party libraries, or Open Source, or ANY popular templating engine.

Let me share an example, on some super popular websites like Twitter, Instagram, GitHub, Facebook and Google+―you’ll find notifications, activity streams and other major functionality/features. Now let’s break it down:

That comes from Twitter, if you decide to become a translator.

This is what I am interested in:

{tag1} and {code + tag2} others followed {tag3}

Each of these tags is replaced by some data that is then rendered to the page live.

My questions:

  1. Do they store these String Templates in separate files?

  2. If NOT, do they store these String Templates in one single file like an array,
    which they open and read from on page load and then store into the browsers
    session for faster access?

  3. Or is there a different way of doing this?

Again, no third-party open source stuff, as I am building my own stuff. I am just curious around, storing, maintaining and using these String Templates later.

Maybe you should ask Twitter how they do it?

Scott

1 Like

LOL. Seriously, If I knew, I wouldn’t be asking here. I am not interested in how Twitter is doing it. My interest, is to get advice and tips, and learn from some better efficient solutions. Now as I already wrote earlier, I have never dealt with something like this before, therefore, I’d be happy to know more.

Still NOT OUT FOR third-party template engine or anything in open source.

Well, with the way you’ve addressed yourself to this community, I highly doubt you’ll get better answers than what you already got in the other thread you started.

Scott

2 Likes

The other thread FAILED. This one addresses my concern better. I have zero issues coding this, but I need to know what’s the best way in practice; e.g. storing in separate files, or storing in an array inside a file (that is read I/O NOT included using a standard PHP include functionality), or using the database (I am not a big fan of this one).

Is the program you want to create going to have to scale well? If the answer is yes, you won’t be able to avoid the database as the source of persistence. With PHP, you’ll probably need a caching scheme too.

How many phrases will your application have? The more you have, the more you need to think about file or record size and I/O. In other words, with a large number of phrases, you’ll more than likely need to split up the data.

Scott

1 Like

YES, YES, YES. That’s the plan which I hope for. So database is a preferred way of going? What about loading time and performance? Caching Schema, I had Memcached (http://memcached.org/) in my mind at some later stage.

Currently, I am preparing phrases of activities (that are later used in generating an activity feed/stream). So for now there are a few, as I am just testing some array manipulation algorithms that I have written. But there are going to be more phrases prepared later which I will use depending on a user’s activity.

Almost certainly yes, they do. For an example, reddit’s source is available to browse.

@Jeff_Mott What happened to the rest of your reply?

I decided it was off-topic given the specific question you asked in this thread. In this thread, you didn’t ask how to replace tags with data. Instead, you only asked whether templates should be in separate files.

You could look at what Discourse did, but you’ll have to find a way to utilize such files within PHP (as they’re a Ruby application)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.