2985 Posts in 761 Topics by 740 members
Template Questions
SilverStripe Forums » Template Questions » Encapsulate variables in Templates
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 194 Views |
-
Encapsulate variables in Templates

21 September 2011 at 10:16am
I have a field in the database called $RowOffset which is an Integer and I want to use it in an embedded style like this:
<div class="seatsrow" style="margin-left:$RowOffsetpx">
However it doesn’t work as it sees it as a variable called $RowOffsetpx instead of $RowOffset for obvious reasons.
Desired result is
<div class="seatsrow" style="margin-left:20px">
This doesn’t work because of the space:
<div class="seatsrow" style="margin-left:$RowOffset px">
Is there a way to encapsulate the variable say like this:
<div class="seatsrow" style="margin-left:_v($RowOffset)px">
Hope that makes sense.
-
Re: Encapsulate variables in Templates

21 September 2011 at 11:05am Last edited: 21 September 2011 11:05am
You could try putting it in brackets, such as {$Variable}. If that doesn't work, why not create a function in your dataobject file and concatenate the strings together there? Like so:
public function GetRowOffset() {
return $this->RowOffset . 'px';
}Then you could use $GetRowOffset within your control loop.
-
Re: Encapsulate variables in Templates

21 September 2011 at 5:04pm
Like Ryan Said, {$Foo}px should work.
public function GetRowOffset() {
return $this->RowOffset . 'px';
}PROTIP: name it getRowOffset then you can use the slightly nicer string $RowOffset in the template.
-
Re: Encapsulate variables in Templates

18 December 2011 at 3:43pm
You can if using Escaping
<div class="seatsrow" style="margin-left:{$RowOffset}px">
| 194 Views | ||
|
Page:
1
|
Go to Top |



