Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Template Questions

function in other <% control %>


Reply

3 Posts   1519 Views

Avatar
snaip

24 July 2009 at 12:14am Community Member, 180 Posts

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

Avatar
Nathan Cox

31 July 2009 at 5:18pm Community Member, 99 Posts

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.

Avatar
robinp

1 August 2009 at 12:00am Community Member, 33 Posts

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