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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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

3.1.12 Template: use variable as function


Go to End


2 Posts   408 Views

Avatar
timo

Community Member, 47 Posts

7 May 2015 at 9:31pm

Is this possible somehow?

public static $db = array(	
		'Filter' => 'Varchar'
	);

function getCustomFields(){
		
		$filter = new OptionsetField(
					   $name = "Filter",
					   $title = "Filter",
					   $source = array(
						  "Greyscale,0,0,255" => "Greyscale",
						  "Sepia" => "Sepia",
						  "Colorize" => "Colorize"
					   ),
					   $value = ""
					);
					
		$fields = new FieldList();
		$fields->push($filter);
		return $fields;
    }

And use the Variable as a function in a template

<img  src="<% if $Filter %>$CroppedImage(975,200).$Filter().URL<% else %>$CroppedImage(975,200).URL<% end_if %>" >

thanks.timo

Avatar
Pyromanik

Community Member, 419 Posts

8 May 2015 at 12:46am

No.