View previous topic :: View next topic |
Author |
Message |
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Jul 08, 2009 2:41 am Post subject: |
|
|
lorderunion wrote: | I've never really understood why the {php} tag even exists. The whole point of a templating engine is to keep your business logic and views separate. |
It was a very early feature of the engine, long before design principles were completely materialized, and before a lot of the other better options were created. Never use it. |
|
Back to top |
|
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Wed Jul 08, 2009 8:53 am Post subject: |
|
|
You can shorten the code with:
Code: | <select name="pie_type">
{html_options options=$types selected=$smarty.post.pie_type}
</select> |
Please be sure to check the manual for confirmation |
|
Back to top |
|
edank Smarty n00b
Joined: 07 Jul 2009 Posts: 2
|
Posted: Wed Jul 08, 2009 10:22 am Post subject: |
|
|
first of all thanks for the quick response, though i still have a problem.
the select is in a section
Code: |
{section loop=$cart_content name=i}
<SELECT name="shipment_{$smarty.section.i.index}">
..
..
|
from your examples, i tried accessing {$smarty.post.shipment_?}
the '?' is where im stuck. im trying to get the index number, but whatever i tried just got me a blank screen |
|
Back to top |
|
jezjones Smarty n00b
Joined: 14 Jul 2009 Posts: 1
|
Posted: Tue Jul 14, 2009 4:38 pm Post subject: |
|
|
edank : here is a sample of how i have used indexes in sections
Code: |
<{section name=mainData loop=$results}>
<{if $results[$smarty.section.mainData.index].MediaID != $results[$smarty.section.mainData.index_prev].MediaID}>
... other code like <{/if}><{/section}>
|
the MediaID bit is the name of my variable in an associative array.
Also can people stop saying such bad things against {php} because without it smarty will become much more than a template language.
e.g. there is no way to mimic the following php function that controls display logic : in_array. When you are looping through an array (displaying stuff) with section, to check the current value is present in another array (perhaps showing different content depending on auth level)
HTH,
Jez |
|
Back to top |
|
dmm2020 Smarty Rookie
Joined: 29 Nov 2009 Posts: 27
|
Posted: Sun Nov 29, 2009 1:01 am Post subject: |
|
|
Celeb wrote: | Firstly, lose the quotes:
Code: | $band_id = $this->get_template_vars('band_id'); |
Secondly, this doesn't really look like a Smarty job to me. What does copying files have to do with display logic? Move that task to your php files where they belong.
And last but not least: Don't use {php}{/php} blocks. There always is a better way to do the task at hand. To quote it once again: "If the answer is {php}, you're asking the wrong question." |
How do you do this when the smarty variable is an array? For example, I need to convert gameListArray.gameid to $gameid. All attempts I have tried failed. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Nov 29, 2009 8:41 pm Post subject: |
|
|
$gameListArray = $this->get_template_vars('gameListArray');
$gameid = $gameListArray['gameid']; |
|
Back to top |
|
tommix Smarty n00b
Joined: 11 Dec 2009 Posts: 1
|
Posted: Fri Dec 11, 2009 12:38 am Post subject: |
|
|
So can ANYBODY tell how to get smarty loop variable INSIDE the {php} tag???
I CANNOT assign var in php, i must somehow get smarty section loop variable inside the {php} tag. is there any way? |
|
Back to top |
|
sharik Smarty n00b
Joined: 11 Mar 2010 Posts: 1
|
Posted: Fri Mar 12, 2010 9:20 am Post subject: more problem to access smarty variable in php?? |
|
|
i know it is a older one thread... but may be newer one is in problem...
so i leave it for those........ i used:
Code: | {php}
$v1 = $this->get_template_vars('value1');
$v2 = $this->get_template_vars('value2');
$sum=$v1+$v2;
{/php}
|
_________________ Web Programming and SEO Tips |
|
Back to top |
|
demodav Smarty n00b
Joined: 20 May 2010 Posts: 2
|
Posted: Thu May 20, 2010 1:39 pm Post subject: This is better for display all. |
|
|
{php}
$myVars = $this->get_template_vars();
echo "<pre>";
var_dump($myVars);
echo "</pre>";
{/php} |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu May 20, 2010 1:45 pm Post subject: |
|
|
{debug} |
|
Back to top |
|
|