Results 1 to 9 of 9

Thread: Transphporm - A different kind of template engine

  1. #1
    ..would like a shrubbery.
    Posts
    4,745

    Transphporm - A different kind of template engine

    This isn't at all JK related but I thought I'd post it anyway!

    I wrote a template engine for PHP... Yes these are a dime a dozen but this is different. Rather than mixing concerns like this


    Code:
    <h1>{{title}}</h1>
    <p>{{subtitle}}</p>
    {{if %isAdmin%}}
    <div>conditionally show this</div>
    {{/if}}
    Transphporm separates the logic from the markup by using a CSS style syntax. The template looks like this:


    Code:
    <h1>A title</h1>
    <p>sub title</p>
    <div>conditionally show this</p>
    And allows using CSS like syntax, providing the content and logic:

    Code:
    h1 {content: "My Title"}
    p {content: "My Subtitle" }
    div:data[isAdmin=false] {display: none}
    It does a lot more than this, check it out over on github

    https://github.com/Level-2/Transphporm
    TheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWho
    SaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTh
    eJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSa
    ysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJ
    k
    WhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSays
    N
    iTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkW

  2. #2
    Human Computer
    Posts
    2,808
    Sounds perfect for Massassi 2.0. Thanks for volunteering.
    ? :)

  3. #3
    This is nice. Is it possible to add html as content? Or is it always escaped?
    Sorry for the lousy German

  4. #4
    Quote Originally Posted by Mentat View Post
    Sounds perfect for Massassi 2.0. Thanks for volunteering.
    Oh hell no, Massassi 2.0 will be a Perl6 project.
    And when the moment is right, I'm gonna fly a kite.

  5. #5
    ..would like a shrubbery.
    Posts
    4,745
    Quote Originally Posted by Impi View Post
    This is nice. Is it possible to add html as content? Or is it always escaped?
    With the caveat that it currently has to be valid XML (so <img /> instead of <img>) you can use:

    Code:
    div {content: "<strong>bold text</strong>"; format: html}
    The content can be stored in external data and not just a hardcoded string, e.g.


    Code:
    div {content: data(htmlcode); format: html; }
    TheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWho
    SaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTh
    eJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSa
    ysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJ
    k
    WhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSays
    N
    iTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkW

  6. #6
    How do you access nested data elements?
    And when the moment is right, I'm gonna fly a kite.

  7. #7
    ..would like a shrubbery.
    Posts
    4,745
    Quote Originally Posted by gbk View Post
    How do you access nested data elements?
    You can either use a dot or square brackets, they're interchangeable like javascript:

    Code:
    data(foo[bar]);
    data(foo.bar);
    You can also bind a specific variable to an element and it's available in child nodes directly:

    Code:
    div {bind: data(foo);}
    span {content: data(bar); }
    Which will read foo[bar] from the supplied data. This is really useful for re-populating form fields. For example:


    Code:
    echo $template->output(['formdata' => $_POST])->body;
    You can then write a reusable TSS file that can be used to populate any form with a data set:

    Code:
    form {bind: data(formdata);
    /* Set the input's value attribute 
    
    input:attr(value) {content: data(attr(name); }
    This works by reading the input's `name` attribute using `attr(name)` and passing the result of that to the `data()` function which is then looked up in the supplied array.

    What this allows is a reusable TSS:

    Code:
    input[type="text"]:attr(value) {content: data(attr(name); }
    textarea {content: data(attr(name));
    Which can then be used in any other TSS file using:

    Code:
    @import 'form.tss';
    form {bind: data(formdata); }
    and doesn't require the form data to be stored in a specific key in the $data array.
    TheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWho
    SaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTh
    eJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSa
    ysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJ
    k
    WhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSays
    N
    iTheJkWhoSaysNiTheJkWhoSaysNiTheJkWhoSaysNiTheJkW

  8. #8
    Human Computer
    Posts
    2,808
    Quote Originally Posted by gbk View Post
    Oh hell no, Massassi 2.0 will be a Perl6 project.
    Sounds perfect for Massassi 2.0. Thanks for volunteering.
    ? :)

  9. #9
    Hammer and Nail Computing
    Posts
    2,324
    Well, if any of it can unpack an archive and level pack (like GOBs for JK) to give a level submission reviewer an easier time to see all resources so no secret questionable content gets through...

Posting Permissions

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