|
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:
- 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.
- 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.
- 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 |