21278 Posts in 5728 Topics by 2599 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2104 Views |
-
Passing variables from controller to template

8 January 2009 at 12:58am Last edited: 8 January 2009 2:10am
I feel really stupid asking this question, but if I want to make some changes to an existing variable in the controller before it is rendered in the template, such as $Content or $Title or a custom field such as $AuthorName for example, how can I do this? I just can't seem to find instructions on how to do this in the tutorials or the forums. Can someone point me to the right page that explains how to accomplish this?
If someone tells me to RTFM, I'm really sorry that I'm such an idiot, but I just cannot find any information about this anywhere on Google or the Silverstripe tutorials/forums, and I tried really really hard. So would very much appreciate it if you can point me to the right URL.
Thanks!
-
Re: Passing variables from controller to template

8 January 2009 at 8:07am
Just create a method with the same name as the variable that you want to use, ie:
function AuthorName() {
return $this->Author()->Name;
} -
Re: Passing variables from controller to template

4 February 2009 at 10:32pm
Hi,
i think i have the same problem as stinkytofu,
and im not that familiar with silverstripe and the mvc framework.I want to check $MenuTitle string-length to define another Menu CSS class before its been replaced by its Content.
I want to try it by creating a new php-method into my pagetype controller, but i i dont know how to assign $MenuTitle to this funciondoes anybody got a solution for this problem?
greetings from germany.
Sebastian -
Re: Passing variables from controller to template

5 February 2009 at 7:40am
function MenuTitleLength() {
return strlen($this->MenuTitle) > length;
}Then you can use <% if MenuTitleLength %>...<% end_if %> in your template.
The comparison must be done in the controller as the template language doesn't allow inequalities.
| 2104 Views | ||
|
Page:
1
|
Go to Top |


