SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot sanka69's Avatar
    Join Date
    Apr 2003
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    templating logic

    Hi,
    I'm dabbling in Mojavi at the moment, and thinking about the way it's templating engine works, and well, MVC in general.

    When it comes to printing lists of data, my actions gather the data and send it to the view class. What I'm trying to establish is how to approach the development from the view. Take a list of data, this will typically be sent to the view as an Iterator. (The view class, and not the template file) Sending the Iterator itself to the template seems a bit weird, and the designer doesn't really want to know about Iterators. Alternatively, say I had a "printer" class. ie: "UserListTableDisplay" which would generate the html table and dump it to the template.. that's all well and good, but then the designer looses fundamental control over the appearance of that particular table.

    I appreciate this is borderlining a highly discussed area, but I'm trying to work out the boundaries of what I do as a programmer, and when I should passing the buck to the designer. Dynamically populated drop down boxes are all wrapped up in their own little widgets because the designer's already styled an input box at the stylesheet, but tables of data overlaps into the design area considerably.

    In the context of using Mojavi, does anyone have an opinion?

    Thanks,
    Richard

  2. #2
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Personally, I don't see any reason why tabular data could not be represented with templates as well, that is the way I have been handling the problem in the past.
    Garcia

  3. #3
    SitePoint Zealot sanka69's Avatar
    Join Date
    Apr 2003
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quick response

    I'm really getting at, should I give the designer an Iterator object to do with what they need, or should I code some form of widget that gives the designer the markup to display whereever on a page. I suppose the widget could refer to an XSL stylesheet, but overengineering sirens are screaming at me.

  4. #4
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kwartz looks like an interesting take on templates. Basically, it takes two files. One presentation html:

    HTML Code:
    <table>
     <tr bgcolor="#CCCCFF" id="mark:list">
      <td id="mark:name">foo</td>
      <td>
       <a href="mailto:foo@mail.com" id="mark:email">foo@mail.com</a>
      </td>
     </tr>
    </table>
    and one with presentation logic (just a snippet):

    Code:
    #list {
      attrs:  "bgcolor" color;
      plogic: {
        i = 0;
        foreach (member in member_list) {
          i += 1;
          color = i % 2 == 0 ? '#FFCCCC' : '#CCCCFF';
          @stag;    // start tag
          @cont;    // content
          @etag;    // end tag
        }
      }
    }
    And generates a compiled template like this:

    PHP Code:
    <table>
    <?php $i 0?>
    <?php 
    foreach ($member_list as $member) { ?>
    <?php   $i 
    += 1?>
    <?php   $color 
    $i == "#FFCCCC" "#CCCCFF"?>
     <tr bgcolor="<?php echo $color?>">
      <td><?php echo $member["name"]; ?></td>
      <td>
       <a href="mailto:<?php echo $member["email"]; ?>"><?php echo $member["email"]; ?></a>
      </td>
     </tr>
    <?php ?>
    </table>
    See the full example here: http://www.kuwata-lab.com/kwartz/use....html#example2

    Programming language independant too, beause it can generate the compiled templates is multiple languages. It looks nice, and is being actively developed.

    Douglas
    Hello World

  5. #5
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    TemplateView works well for relatively static views, witch just need a few constants changed now and then. However - more complex views (such as a list) mean that you have to put a lot of (presentation-)logic into the template. This is why you often see templates combined with some sort of plugin/widget capability. This is also called a ViewHelper.


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
  •