silverstripe-blocks
silverstripe-blocks copied to clipboard
Adding position template vars to blocks
This makes some common template vars available to the block rendering, making each block aware of its position in the current blocklist (Fixes #76). Vars: $Pos, $Parent (reference to the containing SiteTree object), $TotalItems, $First, $Last, $FirstLast.
Hey awesome, I just tried it out and it didn't seem to work though. If I place $FirstLast in template it's always "first last", $Pos is always "1". Did you test these? Or maybe there's just an issue with my set up I dunno. If yours is definitely fine I'll do a fresh install etc and test again. Thanks!
That's weird... I didn't write unittests, but am using the template vars myself to add a 'Back to top' link after the third block. Are you calling BlockArea('somearea') to get the blocks? (not 'Blocks()' or any other getter)?
And (this template code isn't included on all blocks, hence the output skips a few Pos'es):
Is this something that's currently being worked on? We are running into a situation where some of these vars would be nice to have.
This feature is essential, would love to see this added in the near future. I also had the same issue as sheadawson, it seems the variables are conflicting with one another. I changed Pos to Position and it worked. Many thanks.