silverstripe-blocks icon indicating copy to clipboard operation
silverstripe-blocks copied to clipboard

Adding position template vars to blocks

Open micschk opened this issue 8 years ago • 4 comments

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.

micschk avatar Apr 06 '16 12:04 micschk

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!

sheadawson avatar Apr 06 '16 21:04 sheadawson

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)?

image image

And (this template code isn't included on all blocks, hence the output skips a few Pos'es): image image

micschk avatar Apr 07 '16 03:04 micschk

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.

korthjp17 avatar Dec 30 '16 20:12 korthjp17

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.

BrookeNZ avatar May 05 '17 04:05 BrookeNZ