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

Encapsulate variables in Templates


Reply

5 Posts   727 Views

Avatar
MonkeyFish

21 September 2011 at 10:16am Community Member, 12 Posts

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. :)

Avatar
Ryan M.

21 September 2011 at 11:05am (Last edited: 21 September 2011 11:05am), Community Member, 309 Posts

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.

Avatar
Willr

21 September 2011 at 5:04pm Forum Moderator, 5511 Posts

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.

Avatar
MonkeyFish

26 September 2011 at 12:37pm Community Member, 12 Posts

Chur :)

Avatar
radu706

18 December 2011 at 3:43pm Community Member, 1 Post

You can if using Escaping

<div class="seatsrow" style="margin-left:{$RowOffset}px">