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

Need Help With Template Parsing - Not Sure How to Do

Development and Programming

Zac G.'s avatar
Zac G.
268 posts
16 years ago
Zac G.'s avatar Zac G.

Hi,

I am working on a grade module for EE and I have everything done except for a last bit of the template parsing.

I can get it to display the assignments, the points earned, the possible points, and the grade. However, there are some other things I want to have available like the total of all points earned, the total of points possible, and the person’s final grade.

I have got it working with PHP, but could really use someone with a good understanding of how template parsing works to aid me with these last few features.

Cheers! Zac

       
Robert Wallis's avatar
Robert Wallis
36 posts
16 years ago
Robert Wallis's avatar Robert Wallis

Here’s a quick overview:

$TMPL->tagdata is all the text inside your module tags unparsed.

$TMPL->tagparams is an array of the attributes of your module tag.

$TMPL->swap_var_single(tag, replacement, tagdata) is a helper function that will replace a single tag (one that has no closing complement) with your choice of text. You could write your own helper function if you wanted, but these ones are already written and work well.

$FNS->prep_conditionals(tagdata, array_of_variables) will look for variables inside curly tags for conditional statements (if, else, etc…) and replace the variable names found in the keys of the array with their values. This allows the template designer to add conditional statements that use variables you provide.

Before you return, depending on your circumstances you might need to do this:

$tagdata = str_replace(SLASH, '/', $tagdata);

Lastly, you exit the function by returning a string of the html you created.

return $tagdata;

If your module iterates through records, just copy the $TMPL->tagdata at the beginning of the loop, and append it to the result string.

$tagdata = '';
foreach($data as $d)
{
    $tagdata_data = $TMPL->tagdata;
    // do processing
    $tagdata .= $tagdata_data;
}
// do more
return $tagdata;
       
Zac G.'s avatar
Zac G.
268 posts
16 years ago
Zac G.'s avatar Zac G.

Robert - Thank you so much for taking the time to respond! This is a great explanation and I will come back to it in a bit when I get some time to mess with my module again. Huge thanks!

       

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.