I want to be able to achieve code templating in ASP.NET, with the power of PHP. The following two code files result in the same output, but the PHP one is more elegant, and can even be imported into other PHP files so it can be reused.
ASP.NET:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ASP_dot_NET_test.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"><title></title></head>
<body>
<script runat="server">
delegate void Make_buttons(int count);
</script>
<%
Make_buttons Make_buttons = i =>
{
for (int k = 0; k < 2; k++)
{
%>
<hr />
<button><%= "buy " + i + " candies!" %></button>
<%
}
};
%>
<div>
<%
Make_buttons(count: 5);
%>
</div>
</body>
</html>
PHP:
<!DOCTYPE html>
<html>
<head><title></title></head>
<body>
<?php
function Make_buttons ($i)
{
for ($k = 0; $k < 2; $k++)
{
?>
<hr />
<button><?= "buy " . $i . " candies!"; ?></button>
<?php
}
}
?>
<div>
<?php
Make_buttons(5);
?>
</div>
</body>
</html>
I know about Master Pages, but they accomplish page templating, not code templating like above.
What are some of the best ways I can accomplish this?