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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

can i execute function with variable in template ?

Go to End

10 Posts   4065 Views


Community Member, 181 Posts

11 December 2009 at 5:39am

new problem : )

my funtion

	function showPDF($id) {
		$record = DataObject::get_by_id("File", $id);
		return $record;

in template

        <% if PDFID %>
		<% control showPDF() %>
		<a href="$Filename"><img src="themes/tutorial/images/pdf_ikon.gif" width="32" height="32" /></a> 
		<% end_control %>
        <% end_if %>

and everything works great when i execute showPDF like this: <% control showPDF(204) %>
but when i have: <% control showPDF($PDFID) %> i got an error:

Parse error: syntax error, unexpected '}' in C:\Windows\Temp\silverstripe-cacheC--serwer-strony-ernesto\ on line ....

$PDFID is variable form database


Forum Moderator, 5523 Posts

11 December 2009 at 8:37am

As it says on the documentation page for templates - passing dynamic variables into functions is not supported yet.

ok it works now but i cant use it in other <% control %>

If you want to use the $replace_str on other page controllers other then the OkolicaMapaPage_Controller then it has to be in the model - OkolicaMapaPage class. Controllers aren't passed along when doing controls of other pages.

Go to Top