Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

How to use one smarty file for different .tpl files?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
0rientsieg
Smarty Rookie


Joined: 08 Jan 2014
Posts: 24

PostPosted: Sat Jan 11, 2014 2:23 pm    Post subject: How to use one smarty file for different .tpl files? Reply with quote

Dear All,
Meanwhile I familiarized myself with Smarty and I inserted in a .tpl file text in English or in Thai or in German by including the specific language files in one Smarty initialization file.
But I'm still not satisfied. Before I tried Smarty, I worked for the languages inclusion with php files. I created one php file to be displayed and in addition 1 php file for each of the 3 language with an array per file containing the phrases of a specific language. The required language file I included dependent on the entry in a text file where I stored the language a specific user had chosen at the beginning of the session at the first page of my publication.
I prepared consequently 3 php files, one for English, one for German, and one for Thai and additionally one php file containing the publications with the inserted correct language.
For Smarty I need now one file more, let me call it the the Smarty initialization file.
As on my calling page are at least 7 links for opening files in different languages (equal to the .tpl files) I need now to create in addition 7 Smarty initialization files. That are 7 files more than at the purely PHP solution.
I found already, that it is possible to hand over the name of the language file and in addition the name of the .tpl file to only one Smarty initialization file and it is possible to include the name of the at that time required language file into the Smarty initialization file as well as the name of the correct .tpl file, so that only one initialisation file is required.
But I did not find a way to pass the information language file/.tpl file to the Smarty application. At my web page http://www.moon-and-sun.com/index-en.php are at the left hand side small images showing houses. If somebody clicks at one of these images a .tpl file specific to the image shall be opened in the correct language. I need for Smarty now 6 x .tpl file equal to the php solution. But how can I pass the information to Smarty initialization which .tpl file is required for a specific click?
I do not want to write now 7 Smarty initializations if one obviously can do it. The easiest way would be to create at the time of the click with php a .txt file containing the name of the required language file as well as the name of the correct .tpl file for that specific image. But how can that be achieved?
Does somebody know a solution?
With regards
Siegfried
Back to top
View user's profile Send private message
0rientsieg
Smarty Rookie


Joined: 08 Jan 2014
Posts: 24

PostPosted: Sun Jan 12, 2014 3:59 am    Post subject: How to use one Smarty file for different .tpl dfiles? Soluti Reply with quote

Dear All,
Again I found the solution by myself.
It is possible to add a page name to a html call which can be retrieved. It is like follows:
<a href="http://www.moon-and-sun.com/booking/makewp/input.php?name=lilawadi" >
Retrieving the name and creating with php the name of the required .tpl file looks as follows:
$tplfile = trim($_GET['name'].'.tpl');
With these improvements I can mark which .tpl file is trequired for a call of the Smarty initialization file and can insert the name in the display tag:
$smarty->display($tplfile);
No further investigation necessary for this topic.
With regards
Siegfried
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sun Jun 22, 2014 10:51 am    Post subject: Reply with quote

Just to make you aware, this is a very, very bad idea to pass request variables to the filesystem unchecked.
In your case, I would construct an array of available names and template paths corresponding to them, something like this:

Code:
$tplNames = array(
 'lilawadi' => 'lilawadi.tpl',
);

if(isset($tplNames[$_GET['name']]))
  $tpl->display($tplNames[$_GET['name']]);
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP