View previous topic :: View next topic |
Author |
Message |
frost Smarty Rookie
Joined: 29 Apr 2003 Posts: 13 Location: Canada eh?
|
Posted: Sun May 04, 2003 6:01 pm Post subject: |
|
|
Wom.bat, you include a file with the text?
boots, another question for your method, when you handle the text of a page and it has paragraphs. Do you just have
Code: |
text = <p>this is my my text</p>
<p>this is my my text</p>
<p>this is my my text</p>
|
Or have you come up with another way to do this? _________________ w00t |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 6:06 pm Post subject: |
|
|
hmmm. I still don't think the HTML should be in the config file, but if that's how you want it, then you can use triple quotes:
See: http://smarty.php.net/manual/en/config.files.php
Quote: | If you have a value that spans more than one line, enclose the entire value with triple quotes ("""). |
eg.
Code: | text = """<p>this is my my text</p>
<p>this is my my text</p>
<p>this is my my text</p>""" |
|
|
Back to top |
|
frost Smarty Rookie
Joined: 29 Apr 2003 Posts: 13 Location: Canada eh?
|
Posted: Sun May 04, 2003 6:12 pm Post subject: |
|
|
I agree that the HTML should be in the template files, but I am wondering how else to do this? The only other thing I can think of is perhaps putting a delimeter between each paragraph and having Smarty parse it and putting in the <p> </p> tags...
How have you managed to solve this problem? _________________ w00t |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 04, 2003 6:50 pm Post subject: |
|
|
I think I had it in my mind that you were trying to localize the interface (minimal amounts of text) and that localized application data was being loaded elsewhere. This still works, though it starts to lose merit depending on how much formatting you need to do in your text. If all it is is embedding <p>'s then that's probably okay or you can also create a modifier like nl2br. Say you had $local|nl2p where nl2p wrapped $local in <p> .. </p> and then replaced every \n\n with a <\p><p>. Still, seems wrong.
Wom.bat's method does deserves more consideration . |
|
Back to top |
|
Wom.bat Smarty Pro
Joined: 24 Apr 2003 Posts: 107 Location: Munich, Germany
|
Posted: Sun May 04, 2003 7:02 pm Post subject: |
|
|
no, frost
I'll give you an example:
Code: |
// foo.php
// fetch news in correct language from database
$smarty->assign("newsEntries", $newsEntries);
$smarty->display("foo.tpl");
|
and
Code: |
{* foo.tpl *}
{foreach from=$newsEntries item="newsEntry"}
{$newsEntry.title|escape}{if ($_SESSION.language == "DE")}, geschrieben am {$newsEntry.timestamp|date_format:"%d. %m. %Y, %H:%M"} von {$newsEntry.author|escape}{elseif ($_SESSION.language == "EN")}, posted on {$newsEntry.timestamp|date_format:"%B %d %Y, %H:%M"} by {$newsEntry.author|escape}{/if}
{/foreach}
|
it's that simple... |
|
Back to top |
|
frost Smarty Rookie
Joined: 29 Apr 2003 Posts: 13 Location: Canada eh?
|
Posted: Sun May 04, 2003 7:40 pm Post subject: |
|
|
Thank you Wom.bat this is very helpful! I am still however curious as to how I would create a simple page which only has a few paragraphs on it. _________________ w00t |
|
Back to top |
|
Wom.bat Smarty Pro
Joined: 24 Apr 2003 Posts: 107 Location: Munich, Germany
|
Posted: Mon May 05, 2003 6:20 am Post subject: |
|
|
well, frankly I don't understand what you'd like to know...
a simple page which only has a few paragraphs on it?
could you give a little more details? |
|
Back to top |
|
frost Smarty Rookie
Joined: 29 Apr 2003 Posts: 13 Location: Canada eh?
|
Posted: Tue May 06, 2003 9:36 pm Post subject: |
|
|
Sorry I didn't mean to confuse!
Basically half the pages on my site contain only text. What I need to do is, depending on the language, display the correct text.
So I would have
Code: |
Header
<p>this is some text on my page</p>
<p>which are in the correct language</p>
Footer
|
If all my pages were like this I could include a .tpl file for each page which had {if} statements in them to display the correct text. However I also have pages with tables and PHP scripts. As boots pointed out, having complex HTML inside .tpl files would not be a good idea; it makes it harder to edit...
Code: |
{if...}
complex HTML 1st language
{else}
complex HTML 2nd language
{endif}
|
What i'm asking is what would be the best way to setup my templates and my information so it will be easy to edit. I've looked all over the web and there is lots on Smarty, but little on how people acctually bring their content into Smarty. Maybe it's just something very obvious that I am missing? _________________ w00t |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed May 07, 2003 12:35 am Post subject: |
|
|
frost wrote: | As boots pointed out, having complex HTML inside .tpl files would not be a good idea; it makes it harder to edit... |
I don't think I said that
Its not a good idea to have complicated HTML inside CONFIGURATION files. Template files are just the place for tricky HTML's.
Your situation is different, though. You basically are saying: I have text that DOES NOT need formatting except for paragraph markers.
I say use my method of stashing the text in config files. Go ahead and embed those <p>'s. If not, use my modifier idea. You'll note that Wom.Bat's idea (which you correctly modelled) means that everything stays in one file, which in your case, is probably not such a bad idea.
Here's a tip: since you are passing a $lang identifier to Smarty, you can use the $lang as the compile_id for display(). That will cause Smarty to compile a different version of the template for each language. Very cool! Unfortunately, if you use Wom.Bat's method, that means that anytime you update the page (say to correct a type in one of the languages) it forces a re-compile for all compile_id's.
See: http://smarty.php.net/manual/en/variable.compile.id.php
and http://smarty.php.net/manual/en/caching.php |
|
Back to top |
|
|