GithubHelp home page GithubHelp logo

bigpresh / dancer-template-htmltemplate Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 4.0 164 KB

Dancer::Template::HtmlTemplate - HTML::Template wrapper for Dancer

Home Page: http://search.cpan.org/dist/Dancer-Template-HtmlTemplate

Perl 100.00%

dancer-template-htmltemplate's Introduction

NAME
    Dancer::Template::HtmlTemplate - HTML::Template wrapper for Dancer

DESCRIPTION
    This class is an interface between Dancer's template engine abstraction
    layer and the HTML::Template module.

    In order to use this engine, use the template setting:

        template: HtmlTemplate

    This can be done in your config.yml file or directly in your app code
    with the set keyword.

    Since HTML::Template uses different syntax to other template engines
    like Template::Toolkit, the default layout `main.tt' generated by the
    scaffolding script must be updated to use HTML::Template directives:

        [% content %]

    needs to be changed to:

        <!--tmpl_var name="content"-->

    or

        <TMPL_VAR name="content">

    Future versions of Dancer may ask you which template engine you wish to
    use, and write the default layout and example templates appropriately.

    Also, the current default file extension for template files is `.tt'; at
    the time this template engine wrapper was produced, the template engine
    wrapper could not override default file extensions. This is now
    possible, but I haven't made this change as it would break applications
    relying on the default being `.tt'.

    If you want to change the extension used, use the `extension'
    configuration option, for example, to declare that the extension should
    be `.tmpl':

        template: HtmlTemplate
        engines:
            HtmlTemplate:
                extension: 'tmpl'

    WARNING - Even if you use the default `.tt', you may want to explictly
    set the `extension' setting to indicate that, as future versions may
    default to a more suitable file extension.

Handling nested hashrefs
    Since HTML::Template does not allow you to access nested hashrefs (at
    least, not without switching to using HTML::Template::Pluggable along
    with HTML::Template::Plugin::Dot), this module "flattens" nested
    hashrefs.

    For instance, the session contents are passed to Dancer templates as
    `session' - to access a key of that hashref named `username', you'd say:

        <TMPL_VAR name="session.username">

SEE ALSO
    Dancer, HTML::Template

AUTHOR
    David Precious, `<[email protected]>'

CONTRIBUTING
    This module is developed on Github at:

    http://github.com/bigpresh/Dancer-Template-HtmlTemplate

    Feel free to fork the repo and submit pull requests!

ACKNOWLEDGEMENTS
    Thanks to Damien Krotkine for providing code to flatten nested hashrefs
    in a way that allows HTML::Template templates to make use of them.

LICENSE
    This module is free software and is released under the same terms as
    Perl itself.

dancer-template-htmltemplate's People

Contributors

bigpresh avatar dams avatar dsteinbrunner avatar fcuny avatar

Stargazers

 avatar Ken Huang avatar anton avatar gjskha avatar Maurice avatar  avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

dancer-template-htmltemplate's Issues

Handle Hash of Hash in Tokens

Based on http://www.backup-manager.org/pipermail/dancer-users/2010-October/000381.html

Response from David:
Rather than hardcoding the param names to look at, I think I'd be inclined to
have it automatically flatten any hashrefs in the params into keys in the to
level hashref of params - so, for instance, if the params that were going to
be passed to HTML::Template looked like:

{
foo => 1,
bar => {
baz => 2,
bletch => 3,
}
}

it would get "flattened" into, say,:

{
foo => 1,
bar.baz => 2,
bar.bletch => 3,
}

Having to do that is nasty, but it's a limitation of HTML::Template which
doesn't let you dig into hashrefs, unlike for instance TT, where you can quite
happily use e.g. [% foo.bar %]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.