I’m trying to create a simple plugin that paginates an html string (allowing for AJAX pagination). This is what I’m trying to do…
{exp:cwk_gallery:gallery perpage="9"}
{exp:channel:entries channel="videos"}
<div></div>
{/exp:channel:entries}
{exp:cwk_gallery:gallery}This code will output a span of 20 empty DIVs. I’m simply try to wrap every 9 DIVs in a LI tag to create an unordered list that I can easily paginate with Javascript.
So my plan in the Cwk_gallery plugin is to parse the HTML string to determine where to place the tags. Am I way offbase here? Doing this “the ExpressionEngine way”?
I am retrieving $this->EE->TMPL->tagdata OK, but I just can’t do what I need to do. I’m trying to do AJAX pagination of a gallery of channel entries, but the number of entries shown is different based upon the user’s member_group. The problem is that the member_group stuff is one of the last things parsed. It’s almost like I need to rewrite the channel entries tag completely, I don’t know. My code:
{exp:cwk_galleries:gallery perpage="9"}
{exp:channel:entries channel="recipes" dynamic="off" sort="desc" search:categories="{if freebie_2 == 'bycategory'}{freebie_3}{/if}" search:meals="{if freebie_2 == 'bymeal'}{freebie_3}{/if}" status="open|Open - Admins Only"}
{if status == 'open' OR (member_group == '1' OR member_group == '6' OR member_group == '7')}
{embed="embed/recipe-gallery-entry" entry_id="{entry_id}" dynamic="no"}
{/if}
{/exp:channel:entries}
{/exp:cwk_galleries:gallery}I can successfully parse the “tagdata” variable but the problem is that the member_group stuff is basically the last thing to get parsed so I really have no idea how I’m supposed to go about this, short of rewriting the channel:entries tag completely.
It sucks because I’m a pretty experience CodeIgniter developer but the EE template parsing system is thwarting me at every turn.
Why not remove the entries tag pair and do all the heavy lifting inside of your plugin? You can get the entries using the Database Class (although I’d recommend using the Active Record queries) and have the member groups be a parameter:
{exp:cwk_galleries:gallery perpage="9" member_groups="1|6|7"}And inside your plugin:
$member_groups = $this->EE->TMPL->fetch_param('member_groups', '');
$member_groups = explode('|', $member_groups);
if (in_array($this->EE->session->userdata('group_id'), $member_groups) {
// then...
}Why not remove the entries tag pair and do all the heavy lifting inside of your plugin? You can get the entries using the Database Class (although I’d recommend using the Active Record queries) and have the member groups be a parameter:And inside your plugin:{exp:cwk_galleries:gallery perpage="9" member_groups="1|6|7"}$member_groups = $this->EE->TMPL->fetch_param('member_groups', ''); $member_groups = explode('|', $member_groups); if (in_array($this->EE->session->userdata('group_id'), $member_groups) { // then... }
Yeah I suppose I will need to go about things that way. I was hesitant because I’m not really sure where all the various channel entry data rests in the EE database and I haven’t seen anything in the documentation on that subject. I figured I would instead try to build off the back of the existing channel entries tag. I’ll give this a shot…
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.