Custom conditionals in html content? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Custom conditionals in html content? (/showthread.php?tid=32815) |
Custom conditionals in html content? - El Forum - 08-05-2010 [eluser]CroNiX[/eluser] On a project the client creates page content using the fckeditor. He is now wanting to go above and beyond traditional straight html and use some sort of a custom parser for processing conditional statements within the html. I know vBulletin allows this sort of thing in their templates but I have no idea how to incorporate this. Basically I want to use if/else statements within the html without having to run a dangerous eval(), so I can run the whole text string through a parser and protect certain content. Something like: case 1: show text block only if member of listed groups Quote:<p><strong>This is text everyone can see.<strong></p>Case 2: show text block only if member of listed groups. If not, show alternative. Quote:<p><strong>This is text everyone can see.<strong></p> Does this seem like the best way to accomplish this? If so I would really appreciate some help coming up with the regex to capture the above 2 cases. Regex is still something I have to master and this seems like it would be fairly complex. Thanks for any help or suggestions! Custom conditionals in html content? - El Forum - 08-06-2010 [eluser]CroNiX[/eluser] I got this figured out and thought I'd post in case anyone else could use this. This is useful for a client who has an html editor, or area in their application where they create html markup for dynamic page content, to be able to easily have areas within a page only shown to certain usergroups. This is great for cases where you don't want to restrict the whole page. For instance, the client recently used it on a payment page in a regular website (not shopping cart enabled), where members of paid usergroups get shown certain discounted paypal buttons while unregistered users get shown different buttons. It is to be used in the following ways and bolded text is required. The variables are the usergroups who are allowed to see the html contained. To only display a section of html who is a member of group1. Quote:blah blah html everyone can see... To only display a section of html to multiple groups. Just chain the names of the multiple group names with a semi colon for a separator. Quote:blah blah html everyone can see... If you want to have a section that contains alternate text which is displayed to users who are NOT in the defined groups, use [alt][/alt] tags nested within the [protected][/protected] text area. Quote:blah blah html everyone can see... The only thing you really need to do is figure out how to populate the current users usergroups in the $users_groups array in the beginning of the code. Heres the code. To use it (assuming its in a controller) just: Code: $parsed_text = $this->parse_protected($html_text_to_be_parsed); I hope someone finds it useful. Code: //note: the array users_groups would contain the users current usergroups, |