/*
 * Phil (parsed HTML instruction language) demo
 * © 2008 Achim Settelmeier <phil[a]m1.sirlab.de>
 * 
 */

#include <string>
#include <phil/phil.h>

std::string varCallback(const std::string &varName, void *){
	static unsigned int index=0;
	static std::string fruits[]={ "apple", "kiwi", "strawberry" };
	
	if(varName=="fruit"){
		return fruits[index];
	}else if(varName=="myloop.start"){
		/* reset counter */
		index=0;
		return "1";
	}else if(varName=="myloop.next"){  
		/* iterate three times */
		index++;
		return index<3 ? "1" : "";
	}
	return "";  /* unknown variable, return nothing */
}

int main(){
	std::string input=
		"<html><body><ul>\n"
		"<?phil loop(myloop.start, myloop.next){ ?>\n"
		"    <li>  <?phil echo(fruit); ?>  </li>\n"
		"<?phil } ?>\n"
		"</ul></body></html>\n";
	
	Phil::Phil phil;
	phil.setVarCallback(varCallback, NULL);
	std::string output=phil.process(input);
	
	std::cout << output << std::endl;
	return 0;
}


/*
 Generated output:
 
<html><body><ul>
    <li>  apple  </li>
    <li>  kiwi  </li>
    <li>  strawberry  </li>
</ul></body></html>
 
*/

Generated by cutils 1.6 chilight - Thu Aug 7 00:23:23 2014