17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2985 Views |
-
take data from function in template

5 December 2008 at 11:41pm
Hi!
Silverstripe sintax is a bit complex for me.
So my problem is take data return by function in my template.
If my function return a boolen, and I call $function_name in my template everything is ok.
But if I need a if structure link
<% if function return true %>
...
<% else %>how can pass this value in template?
-
Re: take data from function in template

6 December 2008 at 1:01am
simply use
<% if Property %>
... optional content ...
<% else_if OtherProperty %>
... alternative content ...
<% else %>
... alternative content ...
<% end_if %><% if Property == value %>
<% else %>
<% end_if %>see http://doc.silverstripe.com/doku.php?id=templates
look for 'If blocks' -
Re: take data from function in template

6 December 2008 at 2:42am
ok..I read that document. Now I write my function. If I write $Login it's ok but I can't write
<% if $_SESSION['user']=1 %> in my template.
this is my function:function Login() {
if((Session::get('registrato', false))and($_SESSION['user']=1))
{ return $_SESSION['user'];
}
// Create fields
$fields1 = new FieldSet(
new TextField(
$name = "nome",
$title = "Username:",
$value = ""
),
new PasswordField(
$name = "password",
$title = "Password:",
$value = ""
)
);
// Create actions
$actions = new FieldSet(
new FormAction('doLogin', 'LOGIN')
);return new Form($this, 'Login', $fields1, $actions);
} -
Re: take data from function in template

9 December 2008 at 7:01am
well, using '<% %>' is for control blocks in silverstripe.
what you're trying to get is a variable from plain php, so this might read:<?
if($_SESSION['user'] == 1) {
?>
<p>hello user!</p>
<?
}
?> -
Re: take data from function in template

9 December 2008 at 11:18am
Weird that you're recreating the security system.
Why not use the existing security functionality. Then you can use:
<% if CurrentMember %>
from within your templates.
Then you can use the usual hooks:
<% if CurrentMember %>
Hello $CurrentMember.FirstName
<% else %>
You are not logged in
<% end_if %> -
Re: take data from function in template

9 December 2008 at 11:13pm
I recreate login system because was impossible for me to use again login widget. I need a secondary login area, that open for me 2 new pages, hidden to normal user. Only the privileged user that log in can see that.
| 2985 Views | ||
|
Page:
1
|
Go to Top |



