3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1347 Views |
-
function in other <% control %>

24 July 2009 at 12:14am
hi
why i can't use function inside <% control %> ?
for example i have:
function Wycieczki_sg() {
$doSet = DataObject::get(
$callerClass = "ItWycieczkaPage",
$filter = "Widocznosc = 'Stale'",
$sort = "",
$join = "",
$limit = "3"
);
return $doSet;
}function titlewrap($str) {
$new_title = wordwrap($str, 23, "<br />\n");
return $new_title;
}in template:
<% control Wycieczki_sg %>
<div class="tour" onclick="location.href='$Link'">
<h2><a href="$Link" title="Go to the $Title.XML page">
$titlewrap($Title);
</a></h2>
<a href="$Link" title="Go to the $Title.XML page">
<% control Zdjecie_glowne %>
<img class="" src="$URL" alt="" width="140" height="90" />
<% end_control %>
</a>
</div>
<% end_control %>but $titlewrap($Title); doesn't work
-
Re: function in other <% control %>

31 July 2009 at 5:18pm
I'm seeing two issues here:
1) WHen you're inside the Wycieczki_sg control everything is interpreted in the context of that object (the "ItWycieczkaPage" in this case). So what it's trying to do is call the titlewrap() method of ItWycieczkaPage. To call a method on the "outer" page you need to use $Top.titlewrap()2) As far as I know you can't pass a $Variable as a function argument from the templates, only strings. So $titlewrap($Title) isn't going to work.
I'm guessing what you need to do is put a method like this in ItWycieczkaPage:
function WrappedTitle() {
return wordwrap($this->Title, 23, "<br />\n");
}Disclaimer: I haven't actually tested this.
-
Re: function in other <% control %>

1 August 2009 at 12:00am
Hi
Nathon is right you cann't as far as I know you cann't pass variables in templates. To access titlewrap you actually use $Top.titlewrap
Cheers
Robin
| 1347 Views | ||
|
Page:
1
|
Go to Top |



