How do I change the password?
[SMARTY] Assign a template to a variable....
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

QAIX > PHP web-programming > [SMARTY] Assign a template to a variable.... 28 May 2002 19:37:03

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Moderators:

[SMARTY] Assign a template to a variable....

Gandalf 28 May 2002 19:37:03
 
Hello!>
I have been trying to find out how to do this for nearly half a day now, >but i failed.>Let's say i have a file called index.tpl. And i also have a file which >contains a form called form.tpl.>Now i want the form to be in my index.tpl so index.tpl would look like this:><html> blah blah><table blah blah>><tr>><td> {$form}</td>><tr>><­/table>>.....>
And i do not want the form to be displayed all the time, rather i want the >form to be shown only if $form is TRUE, else it should display a >nonbreakingspace (&nbsp;).>So my two questions are:>How can i display a template inside a template and also how can i tell the >template index.tpl to show either the form or a nonbreakingspace WITHOUT >having to use smarty's {if} {else} etc.. functions (cause the second i >have to do that, it is IMHO not a template anymore, no offence taken).>
I downloaded the docu as a .pdf file and looked through it what seemed to >be forever, but either i totally overlooked it, or what i want is not >possible, which i dought very much :)­>
Any help or tips, hints would be appreciated.>
Thanks a lot in advance!>
Best regards from Vienna,>Jьrgen Hauser

Jьrgen (aka. Frodo the scribe
===================­===
Visit the MECCG Forums at
http://www.coen.at.­tf
Add comment
Ben Godfrey 27 May 2002 21:28:15 permanent link ]
 
So you want a template that behaves differently under different
conditions but you have a policy against using conditionals?

Why can't a "template" contain an if statement. Any template
designer who understands that web pages are code and not just DW
buttons should be able to use it easily. A non-conditional
alternative (if one could be written) would always be much more
complicated because it would be a hack around the language
features.

If you provide good tutorials with examples of how if statements
work then people will learn. If this isn't the reason why you
don't want if statements then tell us a bit more about your
situation.

Ben Godfrey


On Monday, May 27, 2002, at 07:12 PM, Gandalf wrote:
Hello!>>
I have been trying to find out how to do this for nearly half >> a day now, but i failed.>> Let's say i have a file called index.tpl. And i also have a >> file which contains a form called form.tpl.>> Now i want the form to be in my index.tpl so index.tpl would >> look like this:>> <html> blah blah>> <table blah blah>>> <tr>>> <td> {$form}</td>>> <tr>>> </table>>> .....>>
And i do not want the form to be displayed all the time, >> rather i want the form to be shown only if $form is TRUE, else >> it should display a nonbreakingspace (&nbsp;).>> So my two questions are:>> How can i display a template inside a template and also how >> can i tell the template index.tpl to show either the form or a >> nonbreakingspace WITHOUT having to use smarty's {if} {else} >> etc.. functions (cause the second i have to do that, it is >> IMHO not a template anymore, no offence taken).>>
I downloaded the docu as a .pdf file and looked through it >> what seemed to be forever, but either i totally overlooked it, >> or what i want is not possible, which i dought very much :)­>>
Any help or tips, hints would be appreciated.>>
Thanks a lot in advance!>>
Best regards from Vienna,>> JГјrgen Hauser>
JГјrgen (aka. Frodo the scribe> ===================­===> Visit the MECCG Forums at> http://www.coen.at.­tf


--
Smarty General Mailing List (http://smarty.php.­net/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Ben Godfrey 27 May 2002 22:42:39 permanent link ]
 
OK, sorry I didn't answer your questions.

However, if designers are using {section} then they are looking
at the HTML, if they're doing that then if statements are only a
five-minute chat away. With all the template systems the only
feature that can really be made use of by a non-technical
designer is the variable substitution, anything else needs
knowledge of HTML structure, both on the way in to Smarty and
the way out.

I think you're exaggerating a bit when you say people who use
tags are l33t. If they're designing templates that will need
forms sometimes then they understand HTML.

Anyway, my point is that the alternative is not exactly simple
(although it is simpler):

{include file="form.tpl"}

form.tpl contains the if statement:

{if $form ne ""}
<table><tr><td>
<form>
<input name="blah">
</form>
</td></tr></table>
{else}
&nbsp;
{/if}

form.tpl is yours and the designers don't touch it, which makes
it easier, but they will need to add the include magic:

The way around this would be to use {capture} to assign the
output from form.tpl into a variable called $formblock or
something. You would need to include the template designed by
your designers from some template of your own which includes and
captures form.tpl.

Instead of using a top-level developer's template you could also
capture the output of form.tpl using Smarty's fetch method,
which will return the output instead of dumping it to the
browser.

Ben Godfrey


On Monday, May 27, 2002, at 07:56 PM, Gandalf wrote:
I have a policy in using conditions inside a template, my > templates should be containing NOTHING else then HTML and > whatever needs to be displayed inside {}. That is it.> The second i implement logic into a template, the purpose is > lost. The one and only reason why i started to use templates is > because i want to completely strip any html out of my code, and > of course the other way around as well.> I mean, hey, what's the point using> {if $arg=$val}> show this> {else}> show that> {/if}> I could as well do it in my code!>
No, the only thing to be in a template IMHO is {$whatever} and > the {section} {/section} . But that's it.>
Also, i do not want a template that contains differently, i > want a template inside a template, and that template is only to > be shown when the template variable is true, the decision > whether it will be true or not has nothing to do in a template.>
Also, another thing, maybe you have the time to provide your > designers with tutorials about templates, but we for sure do > not have the time.> Why do you think we want to use templates in the first place? > To let the designers do there work and we can do ours.>
The only thing my designers have to do, is designing, nothing > else.We know what the site will look like, they start to design > and put {$whatever} in those placed where input that they > cannot control or that needs to be looped in there HTML code.> Before that we write a Guideline (as in every larger project) > with naming conventions etc.. so we all know what were doing.>
Now you come along trying to tell me i have a policy against > conditionals? Don't think so.>
Please note, im not saying that those functions provided by > Smarty aren't usefull. I can imagine they come in very handy if > you are working on a project on your own, cause then you know > your code and thus also know where you could put conditionals > in the template.>
Another note: This statement of yours> Any template designer who understands that web pages are code > and not just DW buttons should be able to use it easily.>
..is bullex.> What you think? That we are some script kiddies trying to > create a l33t looking PHPNuke with 10 different designs?> A template system in the first place is to strip design from > code. Point. The rest is plain neat stuff.>
Last thing, i asked two question, none of those questions where > answered by you, you also asked me to explain my situation, > which i did.> Are you going to answer my questions now or do you want to keep > babbling?>
JГјrgen Hauser>
At 19:28 27.05.02 +0100, you wrote:>
So you want a template that behaves differently under different > conditions but you have a policy against using conditionals?>
Why can't a "template" contain an if statement. Any template > designer who understands that web pages are code and not just > DW buttons should be able to use it easily. A non-conditional > alternative (if one could be written) would always be much more > complicated because it would be a hack around the language > features.>
If you provide good tutorials with examples of how if > statements work then people will learn. If this isn't the > reason why you don't want if statements then tell us a bit more > about your situation.>
Ben Godfrey>
On Monday, May 27, 2002, at 07:12 PM, Gandalf wrote:>
Hello!>
I have been trying to find out how to do this for nearly half a > day now, but i failed.> Let's say i have a file called index.tpl. And i also have a > file which contains a form called form.tpl.> Now i want the form to be in my index.tpl so index.tpl would > look like this:> <html> blah blah> <table blah blah>> <tr>> <td> {$form}</td>> <tr>> </table>> .....>
And i do not want the form to be displayed all the time, rather > i want the form to be shown only if $form is TRUE, else it > should display a nonbreakingspace (&nbsp;).> So my two questions are:> How can i display a template inside a template and also how can > i tell the template index.tpl to show either the form or a > nonbreakingspace WITHOUT having to use smarty's {if} {else} > etc.. functions (cause the second i have to do that, it is IMHO > not a template anymore, no offence taken).>
I downloaded the docu as a .pdf file and looked through it what > seemed to be forever, but either i totally overlooked it, or > what i want is not possible, which i dought very much :)­>
Any help or tips, hints would be appreciated.>
Thanks a lot in advance!>
Best regards from Vienna,> JГјrgen Hauser>
JГјrgen (aka. Frodo the scribe> ===================­===> Visit the MECCG Forums at> http://www.coen.at.­tf>
--> Smarty General Mailing List (http://smarty.php.­net/)> To unsubscribe, visit: http://www.php.net/­unsub.php>
JГјrgen (aka. Frodo the scribe> ===================­===> Visit the MECCG Forums at> http://www.coen.at.­tf


--
Smarty General Mailing List (http://smarty.php.­net/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Peter Bowyer 27 May 2002 22:52:01 permanent link ]
 Hi,

Not sure I understand you fully but I'll try and answer.

At 20:12 27/05/02 +0200, Gandalf wrote:>>I have been trying to find out how to do this for nearly half a day now, >>but i failed.>>Let's say i have a file called index.tpl. And i also have a file which >>contains a form called form.tpl.>>Now i want the form to be in my index.tpl so index.tpl would look like this:>><html> blah blah>><table blah blah>>><tr>>><td> {$form}</td>>><tr>>­></table>>>.....>>
And i do not want the form to be displayed all the time, rather i want >>the form to be shown only if $form is TRUE, else it should display a >>nonbreakingspace (&nbsp;).>>So my two questions are:>>How can i display a template inside a template and also how can i tell >>the template index.tpl to show either the form or a nonbreakingspace >>WITHOUT having to use smarty's {if} {else} etc.. functions (cause the >>second i have to do that, it is IMHO not a template anymore, no offence taken).

How about removable sections like PHPLib templates?

{section name=foo loop=1 show=$show_foo}
This is my form
{sectionelse}
&nbsp; // Or we could stick this in a separate block...
{/section}

PHP:
if ($form == TRUE) {
$smarty->assign('sh­ow_foo', 1)
}

I think this may do what you want?

The programmer would set $show_foo depending on whether or not that section
(block) should show. The designer doesn't have to worry about it.

Code's untested, but I'm starting to move my templates to this kind of logic...

Peter


--
Smarty General Mailing List (http://smarty.php.­net/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Andrei Zmievski 28 May 2002 16:41:53 permanent link ]
 On Mon, 27 May 2002, Peter Bowyer wrote:> How about removable sections like PHPLib templates?>
{section name=foo loop=1 show=$show_foo}

loop=1 is the default if omitted.
if ($form == TRUE) {> $smarty->assign('sh­ow_foo', 1)

Assign true of false here, please.

-Andrei http://www.graviton­ic.com/

Some people sell razors. Other people sell razor blades. Microsoft
sells shaving cream containing 5% hair growth hormone.
-- sigwinch, posting to Kuro5hin

--
Smarty General Mailing List (http://smarty.php.­net/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Oscar Fernandez Sierra 28 May 2002 19:37:03 permanent link ]
 Hello,

I think the documentation needs an update:

http://smarty.php.n­et/manual/en/languag­e.function.section.h­tml


Attribute Name: loop
Type: [$variable_name]
Required: Yes
Default: n/a
Description: The name of the variable to determine # of loop iterations



The description doesn't seem very exact, because in the example you can see below
you can say loop=1

Greetings.



Andrei Zmievski wrote:>
On Mon, 27 May 2002, Peter Bowyer wrote:> > How about removable sections like PHPLib templates?> >
{section name=foo loop=1 show=$show_foo}>
loop=1 is the default if omitted.>
if ($form == TRUE) {> > $smarty->assign('sh­ow_foo', 1)>
Assign true of false here, please.>
Some people sell razors. Other people sell razor blades. Microsoft> sells shaving cream containing 5% hair growth hormone.> -- sigwinch, posting to Kuro5hin>
--> Smarty General Mailing List (http://smarty.php.­net/)> To unsubscribe, visit: http://www.php.net/­unsub.php

--
Oscar Fernandez Sierra | Mundinteractivos - El Mundo |
Area de Internet | Pradillo, 42 |
oscar@el-mundo.net | 28002 - Madrid (SPAIN, EU) |
http://www.elmundo.­es/ | Tel: (+34) 915864800 (Ext: 4616) |

--
Smarty General Mailing List (http://smarty.php.­net/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


QAIX > PHP web-programming > [SMARTY] Assign a template to a variable.... 28 May 2002 19:37:03

see also:
Ogo and Qmail
Chinese Interface: ZMS2beta
Errors in Configuration-Menus
пройди тесты:
see also:
Hi!I'm ok)Your?
Hi ludi!
Hello

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .