EE Tag Substitution
Posted: 29 July 2008 09:33 AM   [ Ignore ]  
Lab Assistant
RankRank
Total Posts:  105
Joined  07-13-2008

I wasn’t sure of the exact terminology used, so please feel free to rename the title of this post to something more meaningful.

I’ve created a module for the Sphinx full-text search engine. I’m now working on the plugin-side of things - displaying the search results.

I’ve defined a function called ‘search_results’ which right now just returns an array of rows from a DB query. What I want to do is have variables/EE tags in my template and substitute those placeholders for each record in the array.

For example… I want my template to look like the following:

{exp:sphinx:search_results}
{title} <!—I’m not sure how to do the substitution in the background, recursively—>
{/exp:sphinx:search_results}

If I wasn’t dealing with multiple records, I think I could just use preg_replace() - but since there I’m dealing with an array I’m confused and not sure how to go about it.

I look forward to a reply.

Thanks for your help,
Mike

Profile
 
 
Posted: 29 July 2008 09:41 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23547
Joined  05-20-2002

I’m going to shift this to modules- and in truth, if you’re building a module, no need to make a separate plugin to handle the display.  You’d put all of the frontend display bits in the mod.sphinx.php file.

I’d definitely suggest reading over all of the developer docs- the template parser class in particular.  And then- I’d look hard at EE’s mod.search.php file.  It leverages the weblog module in some wise ways.  And for the display end of things, will give you a good hint as to how to proceed.

Make sense?

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 29 July 2008 09:49 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
RankRank
Total Posts:  105
Joined  07-13-2008

Yes, all of my display logic is in mod.sphinx.php. Right now my “search_results” method just returns print_r($records). But I need to iterate through each record and substitute the values with the variables in the template. This is where I’m having troubles.

I’ve had a pretty-good look at the developer documentation, though I’ll spend more time with the Template Parser class. I’ve also been looking at the search module, but cannot understand how the variable interpolation/substitution is done.

If anyone has a small isolated code -example *pleads* that would be very helpful.

Thanks!

Cheers,
Mike

Profile
 
 
Posted: 29 July 2008 09:53 AM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6610
Joined  04-15-2006

Hi Mike,

This page here should help out a little. I have written a few plugins and one extension, never any modules though as of yet wink and this is what I read to get an understanding of the system. Also a lot of help from people on the forums here! wink

Hope that helps.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 29 July 2008 10:02 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
RankRank
Total Posts:  105
Joined  07-13-2008

Thanks Mark… I was just reading that page when your reply notification came in! smile

I hope that that documentation on that page (for the Template Parser class) is updated for more examples. For example, I see that some functions (such as var_swap) are not documented. I’m diving in though, and will post an example for others if I get a solution in place.

Cheers,
Mike

Profile
 
 
Posted: 29 July 2008 10:05 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  105
Joined  07-13-2008

Foolish me - that method (var_swap) belongs to the Functions class.

Profile
 
 
Posted: 29 July 2008 10:07 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  719
Joined  07-02-2007

If you still not out of it i can lend you a hand. And post some sample code.
Let me know.

 Signature 

Truly ExpressionEngine


Fielder Module ( Mass Custom Fields )
Super Cache (Cache heavy tag output)
reCAPTCHA Extension
Rewrite Module


See all my EE Addons (8)

Profile
 
 
Posted: 29 July 2008 10:13 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
RankRank
Total Posts:  105
Joined  07-13-2008

The solution was simple.

$temp = $TMPL->tagdata;
$tagdata = "";
foreach (
$records as $record) {
  $tagdata
.= $FNS->var_swap($temp, $record);
}
return $tagdata;

Thanks for your help everyone.

Now, on to pagination.. smile

Profile
 
 
Posted: 19 September 2008 12:52 PM   [ Ignore ]   [ # 8 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  423
Joined  12-15-2005

Old thread, but wondering if this module was ever completed and made available publicly? Either freely or paid?

 Signature 

System Info: Production

EE Version:  1.66
Build
:       20081114
PHP Version
: 5.2.5

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65085 Total Logged-in Users: 40
Total Topics: 82223 Total Anonymous Users: 18
Total Replies: 441919 Total Guests: 218
Total Posts: 524142    
Members ( View Memberlist )
Newest Members:  BombermanhaimtuagocsadamVeNeaDoRHildegaardhrtrulzUNFORGIVEN IIIEmmanuelYanYanTomsB