Jump to content
Rikki
 Share


Theme Tip: Using Pages blocks anywhere

Blocks are an extremely popular feature in IPS4, used by a huge number of customers to great effect. They range from feeds of topics, to statistics, to custom blocks that can contain anything you wish. They're a great way to add dynamic content to your community theme.

What many people don't know is that blocks you create with Pages can be used anywhere in your theme, not just in the designated block containers (in the header, footer & sidebar).

 

The {block} tag

It's really easy to do so. Here's the tag you'd use:

{block="block_key"}

That's it! The block_key is the one you specify when you're creating the block in Pages (if you don't specify one manually, Pages will auto-generate one for you).

 

Where can you use them?

Block tags can be used anywhere that template logic is supported. That includes:

  • Theme templates
  • Pages page content
  • Other kinds of templates (e.g. database templates)
  • Even within other blocks!

 

What can you do with them?

The obvious benefit of blocks is that they are reusable, so in any situation where you need the same content duplicated, it makes sense to put the content in a custom block instead, and simply insert it wherever needed. Then if you need to update the content later, you have one place to do so. Custom menus are a great example of reusing blocks; since blocks have full use of template logic, you can build your menu HTML in a block, use HTML Logic to highlight the correct item, and insert the menu block on each of your pages. We use this approach on our feature tour section menu. Here's a snippet of the menu block HTML for that page:

<nav id='elTourNav'>
	<div class='container'>
		<ul class='ipsList_inline'>
			<li><a href='/features/apps' {{if \IPS\Request::i()->path == 'features/apps'}}class='sSelected'{{endif}}>Our Apps</a></li>
			<li><a href='/features/engagement' {{if \IPS\Request::i()->path == 'features/engagement'}}class='sSelected'{{endif}}>Engagement</a></li>
			<!-- ... -->
		</ul>
	</div>
</nav>

 

Blocks are useful beyond that, though. A couple of weeks ago, we showed you how to use HTML Logic to only show content to certain groups. Using blocks is actually an easier way to do this - simply add the content to a custom block, then check the groups who should see it. We use this technique to show a 'welcome to our community' message to guests on our own community. We created our welcome message as a custom Pages block, set it so that only guests have permission to view it, and then added it to our template header. Simple, effective and easy to manage.

That's just two ways you can use blocks - there's many other creative users too! If you've used blocks in an interesting way, share your example in the comments!


×
×
  • Create New...