We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

EE Tag Substitution

Development and Programming

mweichert's avatar
mweichert
68 posts
17 years ago
mweichert's avatar mweichert

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

       
Robin Sowell's avatar
Robin Sowell
13,160 posts
17 years ago
Robin Sowell's avatar Robin Sowell

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?

       
mweichert's avatar
mweichert
68 posts
17 years ago
mweichert's avatar mweichert

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

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

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

       
mweichert's avatar
mweichert
68 posts
17 years ago
mweichert's avatar mweichert

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

       
mweichert's avatar
mweichert
68 posts
17 years ago
mweichert's avatar mweichert

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

       
mweichert's avatar
mweichert
68 posts
17 years ago
mweichert's avatar mweichert

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

       
DEA's avatar
DEA
257 posts
16 years ago
DEA's avatar DEA

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

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.