Jump to content

Invision Community Blog


Managing successful online communities


Theme Tip: Create a per-forum feed block

An enterprise customer recently asked us how to have a different feed block for each of their forums. Their goal was to have each forum show a 'popular topics' block containing topics only from that particular forum. Unfortunately this isn't possible using the standard block manager right now, since each view is treated as one configuration. That means that any blocks added to forum view will show for all forums.

However, as usual in IPS4, some of the more advanced power under the hood does allow you to achieve the same goal - in this case, by using HTML Logic. This technique uses a similar idea to the one I outlined in the Dynamic-ish Forum Feeds blog in May.

 

Creating conditional blocks

The way we would implement this functionality is by creating a custom block that is simply a wrapper for other blocks. This wrapper block will contain HTML Logic that determines which feed block to show, based on some information about the current page.

The first step would be to create standard feed blocks for each of the forums to which this should apply. In our example we're creating 'popular topics' blocks, but it could be anything you wish - the principle will remain the same. Another idea would be to create a 'Topics from other forums' block for each of your forums, whereby in the block configuration, you set it to include topics from all forums except the one in which it will be displayed - a good way of cross-promoting your topics.

In order to include the blocks later, set the template key of each to be forum_x, where x is the ID of the forum in which you will display the block.

forum_x.png

 

Once we've created a block for each forum, the next step is to create our wrapper block, which should be a custom block set to use Manual HTML, with the following code:

{{if request.app == 'forums' && request.module == 'forums'}}
	{{$id = \IPS\Request::i()->id;}}
	{block="forum_{$id}"}
{{endif}}

What's happening here is we're checking the app and module from the page URL are both 'forums', which indicates we're in forum view. We then use the {block} tag to insert the appropriate block based on the ID parameter from the URL.

To use this block, simply save it, then using the Block Manager on the front-end, drag it into the desired location in your forum view.

I hope this quick suggestion gives you some ideas for other ways to create blocks that show contextually depending on what the user is viewing. If you have ideas for interesting ways to use this technique, share them in the comments!

Comments

Recommended Comments

 Unfortunately this isn't possible using the standard block manager right now, since each view is treated as one configuration. That means that any blocks added to forum view will show for all forums. "Unfortunately this isn't possible using the standard block manager right now, since each view is treated as one configuration. That means that any blocks added to forum view will show for all forums."

Any idea when that will change and we can have a block per forum?

Link to comment
Share on other sites

Alright, a slight modification to what @Rikki has above will allow you to use multiple feeds in to your individual forums.  I needed this as I have multiple Pages Databases that we use on one of our websites, and I wanted to pull information from more than 1 location.

{{if request.app == 'forums' && request.module == 'forums'}}
	{{$id = \IPS\Request::i()->id;}}
	{{if $id == '5'}}
		{block="forum_5a"}
		{block="forum_5b"}
		{block="forum_5c"}
	{{endif}}
{{endif}}

Now my ForumID is 5.  So when loading Forum5 in the sidebar it will now load 3 Custom Blocks.
You can extend on this easily enough to have a complete different set of feeds in each forum.

Edited by N4H
Link to comment
Share on other sites

I cant seem to get this to work with an image feed. created an image feed in another block using the default image feed template. Called it in another block with the code above. Tested and the block is being called, must be the code of the image feed.

Link to comment
Share on other sites


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

Important Information

We use technologies, such as cookies, to customise content and advertising, to provide social media features and to analyse traffic to the site. We also share information about your use of our site with our trusted social media, advertising and analytics partners. See more about cookies and our Privacy Policy

×