Forum

Thread tagged as: Question

Can I access content from within a block in my template?

Is it possible to grab a few content items from within a block if that block is included in the template I am trying to access it from? I know the reverse is possible but can't find any documentation to go the other way.

Mathew Doidge

Mathew Doidge 2 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Could you clarify what you mean by "grab a few content items from within a block"? What are you trying to do?

I have a block which lets users make a heading which has an unique ID for which I want to create a navigation output that anchors to these headings. Im trying to workout the best approach as at the moment the heading anchor is a block (with many other blocks for different types for content). My idea was to perhaps grab the headings entered in the anchor heading block type and pull them out into the template to see if i could loop over them to make a nav.

Though I get the feeling i may have to do this externally from the template then pipe it back in, perhaps?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I would use a second template with a stripped down version of those same blocks to output the links.

Thanks Drew. I was over thinking this one massively.

I never thought of pulling out the block like this, for some reason I was treating it as some special type of content that I could only access via stripping down the main template externally. Anyhow, I made a new template that just had my block inside it and was able to build my navigation that way.

Thank you!