3212 Posts in 847 Topics by 809 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 991 Views |
-
Variables in nested controls

7 May 2011 at 7:14am Last edited: 7 May 2011 7:15am
I have a include template where I have a nested control and the child control is a function that takes in a parameter.
I need to pass in a parameter via a variable in the parent control, but I can not get this to work.
Here's a stripped down example of what I've done so far:<% if GetProductSubPageOverview %>
<% control GetProductSubPageOverview %>
<div id="$URLSegment" class="tabPage typography">
<div style="position:relative; width:242px; height:181px;" id="overviewImgs">
<p>$PictureURL</p>
<% control Top.getImagesFrom(Top.PictureURL) %>
<p>$Parent.PictureURL</p>
<img style="display:none;" src="$URL" alt="" width="930" height="200"/ >
<% end_control %>
</div>
$Content
</div>
<% end_control %>
<% end_if %>
Now, I've been google searching and I found out about the $Top and $Parent variables and that's how I got as far as getting the Top.getImagesFrom function to run in the nested control (if I pass in a simple string it all works). However, if I put in the 'Top.PictureURL" you see in the code, nothing is passed to the function. Note the "<p>$PictureURL</p>" does return the right variable, so I know I'm getting my right value until I get to the control. I've tried accessing the variable inside the nested control by the "<p>$Parent.PictureURL</p>" portion of code, but this also doesn't give me any value.
Can anyone tell me how I can access these variables? -
Re: Variables in nested controls

7 May 2011 at 7:43am
you can't put a variable as an argument to a function within <% %>
so..
<% control Top.getImagesFrom(Top.PictureURL) %>
..will not work. Instead you could pre-bundle the information and then parse it in the template. -
Re: Variables in nested controls

7 May 2011 at 9:15am
It took me a while to think through your answer, and I was able to find another post of yours on the site that expanded on your reply:
http://www.silverstripe.org/template-questions/show/13619#post290481
got it working now, though it is kind of sad that the controls cannot read parent variables... -
Re: Variables in nested controls

7 May 2011 at 9:21am
funny but I was thinking of that post! I was a bit terse - as you can see I've answered that question a couple of times. I wish I could easily see my past posts, I'd just like to them each time it comes up again.
anyway glad you've got it working
| 991 Views | ||
|
Page:
1
|
Go to Top |


