SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 45
  1. #1
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parsing ASP.NET templates with PHP

    We are finally there folks (once and for all)! A pre-alpha example of parsing ASP.NET templates with PHP. This is really credit to phpHTMLLib.

    Here's something like an ASP.NET template;

    Code:
    <a id="phpLink" href="http://www.php.net" runat="server">
    <img id="myImg" src="http://static.php.net/www.php.net/images/php.gif" runat="server"></img>
    </a>
    
    <p>This is a test<br />
    
    <a id="mySQLLink" href="http://www.mysql.com" runat="server">MySQL</a>
    Note the </img> is a hack - will be fixing this later (shouldn't be there).

    Here's a PHP script that parses it;

    PHP Code:
    <?php
    // Include PEAR::XML_HTMLSax libraries
    require_once('XML/XML_HTMLSax.php');
    require_once(
    'XML/Attributes_Parser.php');
    require_once(
    'XML/Attributes_Parser.php');

    // Include Sax filters
    require_once('SaxFilters/SaxFilters.php');
    require_once(
    'SaxFilters/HTMLSaxParser.php');
    require_once(
    'SaxFilters/HTMLFilter.php');

    // Include phpHtmlLib library
    $phphtmllib $_SERVER['DOCUMENT_ROOT'] . '/phphtmllib-2.2.4';
    require_once(
    "$phphtmllib/includes.inc");

    // Global variable used to access widgets
    $widgets = array();

    // Get ASPX file
    $aspx=file_get_contents('example.aspx');

    // Fire up the HTMLSaxParser
    $parser=& new HTMLSaxParser($aspx); // Pass by reference critical!

    // Not so pretty hack variable
    $var false;

    // Start the HTMLFilter
    $filter=new HTMLFilter($var);

    // Add the base page widget
    $page = & new PageWidget('ASP.NET to PHP!',HTMLINDENT_NICE);

    $filter->setWidget($page);

    // Set parser listener
    $parser->setListener($filter);

    // Parse the page
    $parser->parse();


    // Modify the widgets using the phpHTMLLib API
    $widgets['phpLink']->set_tag_attribute('alt','PHP');
    $widgets['myImg']->set_tag_attribute('alt','PHP');
    $widgets['mySQLLink']->set_tag_attribute('alt','MySQL');
    $widgets['mySQLLink']->set_tag_attribute('style','background-color: yellow');

    // Get the page widget
    $page = & $filter->getWidget();

    // Display the page
    echo $page->render();
    ?>
    Note the section I've marked with "// Modify the widgets using the phpHTMLLib API" - here I'm updating the tags in the original template.

    Here's the HTML I get back;

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      
      
      <head>
        <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
        <title>ASP.NET to PHP!</title>
      </head>
      
      
      <body>
        
        
        
        <a id="phpLink" href="http://www.php.net" alt="PHP">
                <img id="myImg" src="http://static.php.net/www.php.net/images/php.gif" alt="PHP">
    
          </a>
        
        
        
        <p>
        This is a test
        <br /="1">
        
        
        
        <a id="mySQLLink" href="http://www.mysql.com" alt="MySQL" style="background-color: yellow">MySQL</a>
        
        
      </body>
      
      
    </html>
    Notice in the <a id="mySQLLink" /> tag how the modifications I made above;

    PHP Code:
    $widgets['mySQLLink']->set_tag_attribute('alt','MySQL');
    $widgets['mySQLLink']->set_tag_attribute('style','background-color: yellow'); 
    These have been applied to the finished page.

    Anyway - I've attached what I've got as a ZIP.

    The approach I've used to parsing is using SAX filters, something I did before here. The parser itself is PEAR::XML_HTMLSax (http://pear.php.net/package-info.php?pacid=203) which you'll need installed to run the example. The advantage is this approach works but it's not that fast. A better alternative, once it's evolved a little, would be HTML_Template_Flexy.

    You also need to install phpHTMLLib obviously.

    The point of doing this is (arguably) the best web page design tools out there are coming from Microsoft right now, webmatrix being free to use.

    Also phpHTMLLib is a really excellent PHP class library but at the moment, it's not intregrated with any template engine, which means building web pages has to be done in pure PHP - note something which pleases many designers.

    phpHTMLLib cf ASP.NET system.web.ui Namespaces
    What's most fasincinating is phpHTMLLib is actually richer in some areas than ASP.NET. Aside from being able to construct HTML and XHTML there's also WML and SVG support in there. If you compare the .NET system.web.ui.htmlcontrols namespace with the children of phpHTMLLib::HTMLTagClass, phpHTMLLib is far ahead, supporting basically all HTML tags.

    Comparing the system.web.ui.webcontrols namespace with children of phpHTMLLib::BaseWidget, ASP.NET has alot more to offer (but that's not hard to change).

    Particularily interesting about phpHTMLLib is the DataList class, which shows the possibilities to reproduce some of the ASP.NET webcontrols like DataGrid.

    Anyway this is all hacked code right now. More as it happens.
    Attached Files Attached Files

  2. #2
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by HarryF
    Also phpHTMLLib is a really excellent PHP class library but at the moment, it's not intregrated with any template engine, which means building web pages has to be done in pure PHP - note something which pleases many designers.
    Quite a stumbling block - it would be troublesome to translate every single tag into a function wrapped like a method call. Very methodical...something computers are good at

    If I were to start using that, I'd probably have a textarea for each "widget" for entering HTML + a simplified template language. That would get parsed and turned into "widget" class definitions. Of course you'd need to add syntax for including other widgets, and well it's starting to sound sort of like Smarty, isn't it?

    Regardless, tremendous work, and I could really see this go somewhere useful.
    TuitionFree — a free library for the self-taught
    Anode Says...Blogging For Your Pleasure

  3. #3
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it would be troublesome to translate every single tag into a function wrapped like a method call
    Exactly. But what I've got planned should not involve you having to do any of that. All you'd do is create the template (which is basically plain old HTML plus runat="server" tags appended to the elements you want to be "dynamic") and parse...

    This probably isn't making much sense right now but it's not going to take me long to put together an example which really shows it off.

  4. #4
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, I got lost between this bit
    PHP Code:
    $widgets['phpLink']->set_tag_attribute('alt','PHP'); 
    $widgets['myImg']->set_tag_attribute('alt','PHP'); 
    $widgets['mySQLLink']->set_tag_attribute('alt','MySQL'); 
    $widgets['mySQLLink']->set_tag_attribute('style','background-color: yellow'); 
    and the phpHTMLLib docs. It's starting to make more sense now.
    TuitionFree — a free library for the self-taught
    Anode Says...Blogging For Your Pleasure

  5. #5
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To quote Sun Tzu: "Know your enemy. Know yourself" (in other words I have to confess to owning a copy of ASP.NET in a Nutshell).

    Basically the real "parser" is this file: require_once('SaxFilters/HTMLFilter.php');

    Every time it encounters a tag with the attribute runat="server" is instantiates the corresponding phpHTMLLib "widget" and makes that widget available in the $widgets array (treating it as a global variable - another hack but perhaps a necessary one). The index it assigns to the object in the $widgets array is determined by the id attribute of the tag.

    Once it's finished parsing the page, you have the possibility of making further modifications to the "widget" as in the that example. That means you can respond to incoming "events" within your code e.g.;

    PHP Code:
    if ( isset($_GET['color'] ) ) {
        
    $widgets['mySQLLink']->set_tag_attribute('style','background-color: '.$_GET['color']);

    What's also nice about phpHTMLLib is the API is very different to the ASP.NET API (arguably better suited to PHP which is naturally a more flexable language). There's not chance for MS to claim patent violation on their API.

  6. #6
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    At the moment I can't see myself having a use for this;

    Although well done anyway for attempting it; and getting it to run in PHP;

    That's not to say I will never use it though; who know's what's around the corner...

    One day I may have to use a .NET template ? This'll certainly help a lot from point of view of using PHP.

    Great Stuff

  7. #7
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just out of curiosity, how would the above interpret something like this?
    Code:
    <asp:Calendar id="cal" SelectionMode="DayWeekMonth" 
    ShowGridLines="true" ShowNextprevMonth="true" CellPadding="7" 
    CellSpacing="5" DayNameFormat="FirstTwoLetters" FirstDayOfWeek="Monday" NextPrevFormat="CustomText" 
    NextMonthText="Next &gt;" PrevMonthText="&lt; Prev" 
    onSelectionChanged="SelectionChanged" onDayRender="DayRender" 
    
    onVisibleMonthChanged="VisibleMonthChanged" DayHeaderStyle-
    BackColor="Black"
     DayHeaderStyle-ForeColor="White" 
    DayHeaderStyle-
    Font-Name="Arial Black" runat="server">
    <DayStyle BackColor="White" ForeColor="Black" Font-Name="Arial" />
    <NextPrevStyle BackColor="DarkGray" ForeColor="Yellow" Font-Name="Arial" />
    <OtherMonthDayStyle BackColor="LightGray" ForeColor="White" Font-Name="Arial" />
    SelectedDayStyle BackColor="CornSilk" ForeColor="Blue" Font-Name="Arial" Font-Bold="true" Font-Italic="true" />
    <SelectorStyle BackColor="CornSilk" ForeColor="Red" Font-Name="Arial" />
    </asp:Calendar>
    I'm just curious, because you said two things in your post that caught my attention (Harry): one was that it seemed like you were saying .NET only used runat="server" as the main tag attribute. The second was that:
    What's most fasincinating is phpHTMLLib is actually richer in some areas than ASP.NET. ... Comparing the system.web.ui.webcontrols namespace with children of phpHTMLLib::BaseWidget, ASP.NET has alot more to offer (but that's not hard to change).
    I'd think you'd understand by now that the base principle of .NET isn't to be everything to everyone, but for everyone to figure out what works for them.

    As such, I think this is great, if it works properly (which is why I posted the example above, which allows designers to code teh templates as they see fit without worrying about the end HTML, obviously a good thing as it allows folk to versioning up to XHTML or across to another language unlike HTML at all someday without any issues whatsoever).

    Anyways, I'm just curious as I've never seen this in action [img]images/smilies/smile.gif[/img]

    J
    Last edited by M. Johansson; Nov 20, 2003 at 10:19.
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  8. #8
    Talk to the /dev/null Theiggsta's Avatar
    Join Date
    Mar 2001
    Location
    Tampa, FL
    Posts
    376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey uhm harry why the heck cant you use my SAX code?

    its fast and uses SAX style callbacks, I just never finished the extension return system.
    Aaron "Theiggsta" Kalin
    Pixel Martini
    Ruby and Rails Developer

  9. #9
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey uhm harry why the heck cant you use my SAX code?
    Cause I have to reinvent the wheel Will take another look at it promise (never really got round to it I'm afraid).

    seemed like you were saying .NET only used runat="server" as the main tag attribute.
    What I was trying to say is the runat="server" is the attribute .NET looks for to "trigger" the "binding" of the tag to an underlying control class, when parsing an ASP.NET page. Any tag without the runat="server" attribute (as far as I know) is basically ignored and treated as normal HTML. Having said that, looking at your example (thanks) it seems that sometimes, when inside a control tag, .NET "captures" further tags that appear and uses them to further tell the control what to do.

    The example you gave. Well phpHtmlLib doesn't have a calendar widget right now (that would probably be a tough one to implement) but in terms of what the template parser would do with your example (assuming a calendar widget existed);

    The example again;

    Code:
    <asp:Calendar id="cal"
        SelectionMode="DayWeekMonth"
        ShowGridLines="true"
        ShowNextprevMonth="true"
        CellPadding="7"
        CellSpacing="5"
        DayNameFormat="FirstTwoLetters"
        FirstDayOfWeek="Monday"
        NextPrevFormat="CustomText"
        NextMonthText="Next &gt;"
        PrevMonthText="&lt; Prev"
        onSelectionChanged="SelectionChanged"
        onDayRender="DayRender"
        onVisibleMonthChanged="VisibleMonthChanged"
        DayHeaderStyle-BackColor="Black"
        DayHeaderStyle-ForeColor="White"
        DayHeaderStyle-Font-Name="Arial Black"
        runat="server">
        <DayStyle
            BackColor="White"
            ForeColor="Black"
            Font-Name="Arial" />
        <NextPrevStyle
            BackColor="DarkGray"
            ForeColor="Yellow"
            Font-Name="Arial" />
        <OtherMonthDayStyle
            BackColor="LightGray"
            ForeColor="White"
            Font-Name="Arial" />
        <SelectedDayStyle
            BackColor="CornSilk"
            ForeColor="Blue"
            Font-Name="Arial"
            Font-Bold="true"
            Font-Italic="true" />
        <SelectorStyle
            BackColor="CornSilk"
            ForeColor="Red"
            Font-Name="Arial" />
    </asp:Calendar>
    In PHP terms this could be something like;

    PHP Code:
    <?php
    // Instantiate the fictional Calendar widget
    $cal = & new CalendarWidget();
    $cal->SelectionMode="DayWeekMonth";
    $cal->ShowGridLines="true";
    $cal->ShowNextprevMonth="true";
    $cal->CellPadding="7";
    $cal->CellSpacing="5";
    $cal->DayNameFormat="FirstTwoLetters";
    $cal->FirstDayOfWeek="Monday";
    $cal->NextPrevFormat="CustomText";
    $cal->NextMonthText="Next &gt;";
    $cal->PrevMonthText="&lt; Prev";
    $cal->onSelectionChanged="SelectionChanged";
    $cal->onDayRender="DayRender";
    $cal->onVisibleMonthChanged="VisibleMonthChanged";
    $cal->DayHeaderStyle-BackColor="Black";
    $cal->DayHeaderStyle-ForeColor="White";
    $cal->DayHeaderStyle-Font-Name="Arial Black";

    // Add the styles (using another fictional widget)
    $cal->DayStyle=& new TableItemStyle();
    $cal->DayStyle->BackColor="White";
    $cal->DayStyle->ForeColor="Black";
    $cal->DayStyle->Font-Name="Arial";

    $cal->NextPrevStyle=& new TableItemStyle();
    $cal->NextPrevStyle=BackColor="DarkGray";
    $cal->NextPrevStyle=ForeColor="Yellow";
    $cal->NextPrevStyle=Font-Name="Arial";

    $cal->OtherMonthDayStyle=& new TableItemStyle();
    $cal->OtherMonthDayStyle->BackColor="DarkGray";
    $cal->OtherMonthDayStyle->ForeColor="Yellow";
    $cal->OtherMonthDayStyle->Font-Name="Arial";

    $cal->SelectedDayStyle=& new TableItemStyle();
    $cal->SelectedDayStyle=BackColor="CornSilk";
    $cal->SelectedDayStyle=ForeColor="Blue";
    $cal->SelectedDayStyle=Font-Name="Arial";
    $cal->SelectedDayStyle=Font-Bold="true";
    $cal->SelectedDayStyle=Font-Italic="true";

    $cal->SelectorStyle= & new TableItemStyle();
    $cal->SelectorStyle=BackColor="CornSilk";
    $cal->SelectorStyle=ForeColor="Red";
    $cal->SelectorStyle=Font-Name="Arial";
    ?>
    In the above example I'm pretending that parts of the .NET class library exist in PHP.

    With phpHtmlLib the API is different - in fact you add attributes with generic methods like set_tag_attribute() and set_tag_attributes() which allows you to pass an array.

    The calendar control would be an extension of phpHtmlLibs BaseWidget, this being something equivalent to the system.web.ui.webcontrols namespace although as you can see, phpHtmlLib doesn't have anywhere near as many widgets as ASP.NET has available. Thats where most of the effort would have to go.

    Phew. Rant over. Baby calls!

  10. #10
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Cool I wasn't picking on particular widgets, was just curious Almost seems the opposite of what you'd be looking for, going back to a previous templating discussion...

    With templates you're looking for the designer to have the ability to control things without worrying about code. Doesn't the above example stop this from happening?

    I guess ultimately it would be to PHP's benefit if you could simply assign a PHP file to parse out .NET files.

    J
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  11. #11
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess ultimately it would be to PHP's benefit if you could simply assign a PHP file to parse out .NET files.
    Exactly. The ability to drag and drop pages with a tool like Web Matrix will suit some (OK not me but my artistic flair is 0 - I tend to churn out barely acceptable hand coded pages). In fact the incentive for this comes from my job where I've got someone used to drag and drop desktop GUI design demanding something to do web pages with.

    And of the template markups I've seen, ASP.NET is by far the most attactive, being fundamentally HTML will minor add ons and no "control logic".

    I.e. none of this;

    Code:
    {if:foo=bar}
    Hello World!
    {endif}
    An interesting read from one of PHP's own (Sterling Hues works on the core of PHP more or less): http://www.edwardbear.org/blog/archives/000189.html

    Anyway - really have to stop before I end up as a very irresponsible father.

  12. #12
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Interesting cross-linkage *L*

    J
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  13. #13
    SitePoint Guru
    Join Date
    Nov 2002
    Posts
    841
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by HarryF
    And of the template markups I've seen, ASP.NET is by far the most attactive, being fundamentally HTML will minor add ons and no "control logic".
    Amen!

  14. #14
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was working on a very similar template engine a little while ago, however tags had server id's instead of the runat="server", so if a tag had a server:id="", it would create a new object which could control the html within that object, add html, change attributes, etc.

    I never really did finish it though. It was going to be version 2 of my Template-X template parser... Maybe I'll look into it again sometime in the future...

    Anyways: sounds cool Harry.
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  15. #15
    SitePoint Enthusiast escape164's Avatar
    Join Date
    Dec 2002
    Location
    Colorado, USA
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    I have used phpHtmlLib for a number of projects and I love it. The only problem I have is that other people find it hard to learn, and the designers that I work with can't use it very easily.

    This approach is very interesting, do you think it would be possible with just HTML instead of using ASP.NET? I have been analyzing your code, and it would seem that this would be very easy, but I have to admit, the Sax stuff is a little over my head.

    I would guess that the possibilities could also extend beyond this, as in using phpHtmlLib to create PHP-GTK projects, or XUL documents. phpHtmlLib is very extensible, and with it's new Form classes, it has become a very useful and timesaving tool for me. I am excited to see what other uses it has in store in the future.

  16. #16
    SitePoint Enthusiast
    Join Date
    Jan 2003
    Location
    San Diego
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I had a parser that looked for specific XML tags, and would replace the tag with PHP. For example:
    PHP Code:
    <echobox title="My Title">Main text</echobox
    With a config file that looked like this:
    PHP Code:
    <root>
      <
    tag name="echobox">
        <
    startphp>
        <![
    CDATA[
        <
    table border=1><tr><td bgcolor="#cccccc">
        <
    h2>#title#</h2>
        
    </td></tr><tr><td>
        ]]>
        </
    startphp>
        <
    endphp>
        <![
    CDATA[
        </
    td></tr></table>
        ]]>
        </
    endphp>
      </
    tag>
    <
    root
    Prints out:
    PHP Code:
    <table border=1><tr><td bgcolor="#cccccc">
        <
    h2>My Title</h2>
        </
    td></tr><tr><td>
        
    Main text
        
    </td></tr></table
    I'll post the code if someone wants...
    Kyle Maxwell
    www.kylemaxwell.com

  17. #17
    SitePoint Zealot marcoBR's Avatar
    Join Date
    Jun 2002
    Location
    Brazil
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by HarryF
    And of the template markups I've seen, ASP.NET is by far the most attactive, being fundamentally HTML will minor add ons and no "control logic".

    I.e. none of this;

    Code:
    {if:foo=bar}
    Hello World!
    {endif}
    Sorry for my ignorance and lazy, but I'm not understanding exactly how the parser substitute logic in templates. For example, assume the designer want to achieve the following code:

    Code:
    {if:image}
    <table border="0"><tr><td align="center">{image}</td></tr></table> 
    {else}
    <p align="center"><font color="red">No Image</font></p>
    {endif}
    Note that designer has total control over design(html code) between the {if:image} and {endif} tags, thus how to maintain this *freedom* for it using asp.net or your asp.net like parser???

    Hope you understood... my english is terrible.
    Last edited by marcoBR; Jun 7, 2003 at 12:42.

  18. #18
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    In ASP.NET you have DataRepeaters and stuff, so you'd just instantiate the DataRepeater and in your code-behind do the actual logic.

    .NET highly encourages separation of logic from design, and even business from presentational logic. So, place your design elements, and .NET can do the rest.

    In reality, so long as you table is properly named, the code-behind can generate stuff into it, but the DataRepeater is generally more widely used

    J
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  19. #19
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This approach is very interesting, do you think it would be possible with just HTML instead of using ASP.NET? I have been analyzing your code, and it would seem that this would be very easy, but I have to admit, the Sax stuff is a little over my head.
    Certainly it could be used with plain HTML, as it has the advantage of seperating logic from presentation as Jeremy points out.

    The ASP.NET specific syntax is not a requirement as such (although it would allow us to use the .NET tools) but some extra syntax, over HTML, would be needed for implements controls (widgets) that make things like generating tables, calendars etc. simpler.

    I would guess that the possibilities could also extend beyond this, as in using phpHtmlLib to create PHP-GTK projects, or XUL documents. phpHtmlLib is very extensible, and with it's new Form classes, it has become a very useful and timesaving tool for me. I am excited to see what other uses it has in store in the future.
    Definately. It's already there with WML and SVG. May be the author can be convinced to implement XUL at some point.

    That example Marco gives is "doable" with this but in a different way;

    Code:
    {if:image}
    <table border="0"><tr><td align="center">{image}</td></tr></table> 
    {else}
    <p align="center"><font color="red">No Image</font></p>
    {endif}
    You'd have a template might be like this;

    Code:
    <table id="imageTable" border="0" hidden="true" runat="server">
        <tr>
            <td align="center">
                <img id="myImage" runat="server">
            </td>
        </tr>
    </table> 
    
    <p id="noImage" align="center" runat="server"><font color="red">No Image</font></p>
    Note the "hidden" attribute of the table.

    Now your code which "manipulates" this template might look like;

    PHP Code:
    if ( isset($image) ) {
        
    $widgets['imageTable']->hidden=false;
        
    $widgets['myImage']->src=$image;
        
    $widgets['noImage']->hidden=true;

    As Jeremy points out, this makes a better seperation of controlling logic from template. Certainly for designers it may be confusing (think .NET's been struggling to convince web developers as a result) but it does make a very nice divide between designers and developer.

    And does a designer really want to care if there is an image or not? The designers brief may be just "create a template for an image and another for when there's no image".

  20. #20
    SitePoint Enthusiast escape164's Avatar
    Join Date
    Dec 2002
    Location
    Colorado, USA
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might be a little bit off the subject, but one technique that the typo3 project does that I really like is they have a 'module' built into their CMS that parses an HTML file, and uses html comment tags to decide where the dynamic PHP data is inserted.

    For example:
    Code:
    <html>
      <head>
        <title><!-- TITLE BLOCK --></title>
      </head>
      <body>
      <!-- CONTENT BLOCK ONE -->
      </body>
    </html>
    The typo3 project uses their own typoscript to decide where certain content elements go, but in my quest to find an easy solution to completely seperate the designers work from the developer, there seemed some promise here.

    If you could parse this html document into a phpHtmlLib object, insert the content in the correct places, then output it correctly, I think that you would be onto something.

    I see this as a very similar project compared to what Harry has done up above, but just takes the ASP.NET element out of it. This would allow the designer to create pages with Dreamweaver, or whatever, place them into a directory where they were parsed, and the code would take care of the rest.

    I realize that the whole point of this thread was to try and tie ASP.NET together with PHP, and I think that's great, but getting my designers to learn ASP.NET, AND try to get them to use different tools, AND try to get them to understand the entire ASP.NET widget set is slightly unrealistic.

    Just trying to use your ideas to bring the entire thing a little closer to home.

    References:
    Typo3 Tutorial: Modern Template Building

  21. #21
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting. From a quick glance seems the typo template doesn't resort to placing control logic in the template which is good but you still have to populate a bunch of variables which will be inserted into the template.

    The approach here is a little different. The template is what defines which "code behind" classes get loaded as the template is parsed. After parsing, the instantiated objects are available to your script for further modification.

    Although I'm aiming at ASP.NET syntax, there's nothing to prevent this approach being used for something phpHTMLLib specific.

    Certainly the widgets currently available in phpHTMLLib are different to ASP.NET's webcontrols and would require a different syntax to instantiate them.

  22. #22
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On a somewhat related thing, I found something similar to this for Java as well: Tapestry. It uses a very similar concept with "jwcid" tags.

    Tapestry can be found here: http://jakarta.apache.org/tapestry

    I have installed it and am currently looking into it and it also seems as a very nice to keep the logic out of the templates.

  23. #23
    SitePoint Zealot marcoBR's Avatar
    Join Date
    Jun 2002
    Location
    Brazil
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice post Chris! Really Tapestry has an interesting way to maintain logic completely separeted from template and it seems easier for designer learn it.

    Certainly i'll review my template system to adopt Tapestry concepts.

  24. #24
    SitePoint Wizard gold trophysilver trophy
    Join Date
    Nov 2000
    Location
    Switzerland
    Posts
    2,479
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Turns out (after fascinating discussion I had at the weekend) the Sun have caught on to what MS has done with ASP.NET: Java Server Faces. From this OReilly article, here's a JSF page;

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    **<head>
    ******<title>A Simple JavaServer Faces Application</title>
    ** </head>
    
    ** <body>
    ******<%@ taglib uri="http://java.sun.com/j2ee/html_basic/" prefix="faces" %>
    
    ******<font size="4">Please enter your name and password</font>
    ******
    ******<faces:usefaces>
    ******** <faces:form id="simpleForm" formName="simpleForm">
    ************<table>
    ************** <tr>
    ******************<td>Name:</td>
    ******************<td><faces:textentry_input id="name"/></td>
    ************** </tr>
    
    ************** <tr>
    ******************<td>Password:</td>
    ******************<td><faces:textentry_secret id="password"/></td>
    **************</tr>
    ************</table>
    
    ************<p><faces:command_button id="submit" commandName="Log In"/>
    ******** </faces:form>
    ******</faces:usefaces>
    ** </body>
    </html>
    [Minus the ***!]
    More at http://www.jamesholmes.com/JavaServerFaces/

  25. #25
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Interesting, Hommage or Inspiration?

    J
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •