Lunarhotel.co.uk

How about a view of the sea of tranquility?
Home Joomla things Conditional Include Plug in for Joomla 1.5
E-mail
Print
PDF
Written by Web Master   
Wednesday, 09 September 2009 13:20
User Rating: / 1
PoorBest 

I came across a requirement to be able to include content items within content items, but only if certain conditions were met.

The base plugin was very kindly provided by kksou (not sure if that one person or a group) Who've written the include content item plugin (www.kksou.com) So thats the back of it broken. All that i have done is edited the regular expression to allow for optional code snippetts to be included, added some processing code, and away we go!

So here's quick run down of the changes:

  1. Line 47. Changed the regular expression to allow for an optional condition to be included. Did this by adding *.*. Im no expert on regular expressions but this seems to do what I want. Im open to suggestions of any better way of doing it.
  2. Line 64 retrieves the condition (if there is one present) using a function I added called get_condition. Does a simple strpos to get the first opening bracket, and then searches for the plugins closing curly brace "}". This ensures I get the whole condition, and not just up to the first ")". Which could happen because there could be a closing bracket in the middle of the condition.
  3. Line 66 Then eval's the condition and calls process if the eval returns true. This is why a return statement MUST be included in the condition, otherwise it will always return false, and the content never displayed

Example uage

{include_content_item_if 144 ($userinfo=& JFactory::getUser();return $userinfo->guest==false)}

 

Will include the contents of article 144 provided the user is logged in (ie. not a guest). Im afraid Im not too familiar with the inner workings of Joomla 1.5 So thats all I can give you for the time being. Additional examples welcome

 

NOTE: While I havent tested this yet (of course Ive tested the plugin) I dont think that plugins included on the content being included will be processed. Im currently trying to think of a way around this.

NOTE: If you're looking for something that can display modules conditionally, Id reccommend Stephen Brandons MetaMod. You can show modules against specific virtuemart products, categories and lots more. It needs a little bit of coding, but if you're not into that, there are lots of examples of rules you can copy and paste straight in. Its Well worth a look

Last Updated on Sunday, 01 November 2009 20:23
 

You must register if you wish to comment

Its official! usernames suck!

12507Check out the 10 mile round trip I had to do to login into a site that was asking for a username and password

Whos online

We have 2 guests online

Joomla EmailAsUsername Testamonials

"Thanks for a great plugin, and speedy helpful support."

"I really appreciate how responsive you have been and I want to reward you by adding a very positive comment on the Joomla site where I found your great plugin"

"Wow, tested it out and works like a champ"

"I had a couple of installation issues which Dylan sorted for me the same afternoon. Superb service for the price."

"Thank you!!!  Best support I have ever had!"

"Thank you soooooo much for your time and effort on this, you're a life saver!....If your ever in the London or Guildford area I'll get the beers in!"