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

Best way to get variable content into template
Goto page Previous  1, 2
 
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 -> General
View previous topic :: View next topic  
Author Message
frost
Smarty Rookie


Joined: 29 Apr 2003
Posts: 13
Location: Canada eh?

PostPosted: Sun May 04, 2003 6:01 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 04, 2003 6:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
frost
Smarty Rookie


Joined: 29 Apr 2003
Posts: 13
Location: Canada eh?

PostPosted: Sun May 04, 2003 6:12 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun May 04, 2003 6:50 pm    Post subject: Reply with quote

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 Wink.
Back to top
View user's profile Send private message
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Sun May 04, 2003 7:02 pm    Post subject: Reply with quote

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
View user's profile Send private message
frost
Smarty Rookie


Joined: 29 Apr 2003
Posts: 13
Location: Canada eh?

PostPosted: Sun May 04, 2003 7:40 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Mon May 05, 2003 6:20 am    Post subject: Reply with quote

well, frankly I don't understand what you'd like to know... Smile
a simple page which only has a few paragraphs on it?
could you give a little more details? Smile
Back to top
View user's profile Send private message
frost
Smarty Rookie


Joined: 29 Apr 2003
Posts: 13
Location: Canada eh?

PostPosted: Tue May 06, 2003 9:36 pm    Post subject: Reply with quote

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? Smile
_________________
w00t Smile
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed May 07, 2003 12:35 am    Post subject: Reply with quote

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 Wink

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
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 -> General All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
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