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
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?
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
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 😉 and this is what I read to get an understanding of the system. Also a lot of help from people on the forums here! 😉
Hope that helps.
Best wishes,
Mark
Thanks Mark… I was just reading that page when your reply notification came in! 😊
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
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.