Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Optimizing my template system 3

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR

Hi guys :)

I'd like to know if there is a way to optimize my template system
wich works as described below.

The only one drawback with this method is that, I have to renumber all
the calls to hd_page_textfill() if I insert a new text string in the
template somewhere else than the end and if I want to respect the order
of appearance in the template at the same time.

My question is : what option could prevent renumbering?

I would also like to avoid string naming (ie : hd_page_textfill('BUTTON_LABEL') )
because it could be time consuming to find a proper name for even the smallest
text string.

Any idea?

Thanks :)


TEXT FILE :

Code:
...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~> xxxxxxxxx.php
( access codes edition page )
Change the access codes
This section allows you to edit your login and/or password.
Login
show / hide
Password
Password preview
SAVE THE CHANGES
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~> xxxxxxxxx.php
( preferences edition page )
Change your preferences
This section allows you to edit your general preferences.
Your surname
Your name
Your email address
Interface colors
Reset with the default colors
SAVE THE CHANGES
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

PHP FILE :

Code:
...
echo"
<div>" . hd_page_textfill(2) . "</div>
<div>" . hd_page_textfill(3) . "</div>
<div>" . hd_page_textfill(4) . "</div>
";
...
 
coming from first principles the only way you have to identify something is via a name or a position in a collection.

translating to your problem: you either need to identify by label or number. the numbering issue seems to be of your own making since you are containing all your text strings in separate php files.

so, if i've understood you correctly, perhaps a solution is for you to keep all your text strings in a delimited flat file. you can then use some php to parse the file into a collection of numbered text labels within a collection of page names.

to add a text string, you would just put it into the right place in your flat file. your rendering code could iterate through the collection too.
 

Thanks jpadie,

There is only a single flat text file (per language) for a whole site.

In the shortened sample above, you have the text of the interface for 2 different pages.

So, currently, I call the text strings by the order of appearance in the text file.

In the first page, a call of hd_page_textfill(3) would output "Login". In the second page, a call of hd_page_textfill(3) would output "Your surname".

If I add "Hello" above "login" in the text file, I would have to renumber hd_page_textfill() in the concerned PHP file. That's what I want to avoid.

I could place "Hello" at the end, but then, it would not respect the order of appearance in the page.

I guess there is no other solution, right?



 
could you apply numeric labels? so if you added Hello to a page you might still be able to give it a label of 5 (as in the 5th or 6th string) even though it is at the top of the file?

 

The numeric labels are a good idea.
But I fear that I couldn't resist the urge to have them ordered. Maybe I'm just sick :(
 
not sure that i can think of a way to meet all of the criteria you're setting. It's a bit like asking how to stay dry whilst walking around in a storm without an umbrella!
 
Instead of passing a numeric line number, maybe you could use a static variable within your hd_page_textfill() routine. Each call could increment the variable, so that a call to hd_page_textfill() with no parameters would just output the next line of text in the file. No numbering necessary in the PHP.

However, if your reason for doing this is to support multiple languages, you might consider using the gettext extension. It's more complex than what you're doing, but it's also more flexible and would probably be easier to deal with code-wise.
 
I agree with jpadie, I would give each line a label and then the contents. That way you can read the lines into an array and access them by name rather than by number:


Code:
label, text
[red]title[/red],Change your preferences
[red]desc[/red],This section allows you to edit your general [red]prefs[/red],preferences.
[red]sur[/red],Your surname
[red]name[/red],Your name
[red]email[/red],Your email address
[red]colors[/red],Interface colors
[red]defcolors[/red],Reset with the default colors
[red]save[/red],SAVE THE CHANGES

when you read it into your PHP script you can then acces them by

$arrayoflines['[red]sur[/red]']
$arrayoflines['[red]defcolors[/red]']
etc...


If you add a new one, you give it a label, and access it using the labe. doesn't matter where it is.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Instead of passing a numeric line number, maybe you could use a static variable within your hd_page_textfill() routine. Each call could increment the variable, so that a call to hd_page_textfill() with no parameters would just output the next line of text in the file. No numbering necessary in the PHP.

AdaHacker,
I thought of this idea, but unfortunately it doesn't work when you have content that is displayed only under certain circumstances with if/else.
 
Vacunita,

You idea is good but naming can become problematic with small bits of text strings like :

"with " . $var . " persons"

I prefer numbers because they don't convey any sort of meaning.

 
sleidia said:
You idea is good but naming can become problematic with small bits of text strings like :

"with " . $var . " persons"

I prefer numbers because they don't convey any sort of meaning.

I'm not sure I understand... how does "with" . $var . " persons" relate to "interface colors" string?

What exactly are you trying to do?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top