7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Using Variables in Template with DataObjectManager
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1002 Views |
-
Using Variables in Template with DataObjectManager

19 January 2011 at 4:12am
Hello,
thanks for the module, it works great!I am using it for a 'NewsHolder' to display pages of a type called 'NewsArticlePage'. These Pages contain multiple Images and some Text. The Images pop up nicely with thickbox. The Images are added to the 'NewsArticlePage' using the DataObjectsManager.
Now all works, except that I cannot use variables from the parent page NewsHolder while inside a nested loop through the ImageDataobjects.
$Top and $Parent do not work.
Lets say I have this in a template NewsHolder.ss
<% control Children %>
$Pos //this gives me the current Position
<% control ImagesToLoopThrough %>
$Top.Pos //this does NOT work
<% end_control %>
<% end_control %>I did a long search and tried out a lot, but could not find a way to access the page variables inside the loop.
Thanks a lot for your help.
Hilde from Germany
-
Re: Using Variables in Template with DataObjectManager

19 January 2011 at 4:45am
Surely your ImagesToLoopThrough object has a $has_one back to NewsArticlePage? Use that.
$NewsArticlePage.Property
(or whatever you named your $has_one)..
--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com -
Re: Using Variables in Template with DataObjectManager

19 January 2011 at 5:57am
Hello and thanks for the quick reply!
It DOES have a $has_one pointing back to its Page.
static $has_one = array (
'MyNewsArticleImage' => 'Image',
'BelongToNewsArticlePage' => 'NewsArticlePage'
);But using it in the template does not work:
<% control Children %>
$Pos //this iterates NewsArticlePages and gives 1,2,3 as wished
<% control NewsArticleImages %>
$NewsArticlePage.Pos // only shows '1'
<% end_control %>
<% end_control %> -
Re: Using Variables in Template with DataObjectManager

19 January 2011 at 6:29am
Oh that won't work. The iterator properties are only available within the active control.
-
Re: Using Variables in Template with DataObjectManager

19 January 2011 at 7:11am
You might be able to write a function on your NewsArticleImage object..
public function ParentIteratorPos() {
return $this->BelongToNewsArticlePage()->getIterator()->Pos;
}<% control NewsArticleImages %>
$ParentIteratorPos // only shows '1'
<% end_control %>Might work... probably won't.
-
Re: Using Variables in Template with DataObjectManager

19 January 2011 at 8:53am
Thanks again for your effort and quick reply.
Trying to get the wished variables with a function throws: "[Notice] Undefined property: ArrayIterator::$Pos"
What then worked was getting the PageID with
public function ParentIteratorPos() {
return $this->BelongToNewsArticlePageID;
}But, in the next nested loop, the context is again lost, as I Iterate through a normal ImageObject
Example:...
<% control NewsArticleImages %>
<td id="image_$ParentIteratorPos"> // i can use it here for id-ing the cell
<% control MyNewsArticleImage %>
$ParentIteratorPos //already no longer accessible
<% control SetSize(800,600) %>
<a href="$URL" class="modal" group="group_ParentIteratorPos"> // i would love to use it here!...
I will try to look deeper into SilverStripe (I just started using it yesterday) and find out if I can access the PageProperties any other way!
Thanks again for your time and good help!
| 1002 Views | ||
|
Page:
1
|
Go to Top |

