Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^5: Here documents in blocks (why templates)

by LanX (Saint)
on Dec 20, 2020 at 19:41 UTC ( [id://11125507]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Here documents in blocks
in thread Here documents in blocks

You seem to think that templates are just about replacing variables.

There are more techniques like "includes", were sub-templates are integrated which have sub-templates and so on.

Or embedding programming code inside the HTML for loops or conditional snippets.

And there is reusability, like hacking once a generic "table" template and applying it to different projects.

I have to admit all of this can also be done with pure Perl and no regexing at all, thanks to it's flexibility.

But a framework has a lot of benefits in a team, for instance I don't have teach my colleagues a bunch of best practices if there is already a well documented trail to do it.

Separated HTML-code is not only easier to edit - if it's well done the browser can display it , my editor can highlight it properly and formatting, validation and indentation is easy.

Last but not least, isolated HTML code can be handled by a web specialist without any knowledge of the controlling programming langue, much like SQL-Statements don't need expertise in Perl. That's the main idea of the MVC pattern.

Example from another perspective ... You've spend much time criticizing the design of the monastery, but it's a monolithic framework in pure Perl written 20 years ago.

We can't simply ask several design expert to overhaul the templates, because a lot of HTML is interspersed inside Perl code. (actually it's even much more complicated, because many people added parts in the past)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^6: Here documents in blocks (why templates)
by Bod (Parson) on Dec 20, 2020 at 23:33 UTC
    You seem to think that templates are just about replacing variables

    No - I know there is much more too it than that...I just don't understand exactly what and how yet. My foray into 'templates' (of a kind) was just about variable replacement and I didn't get any further.

    But a framework has a lot of benefits in a team

    I can totally see that and my limited experience of working in development teams many years ago means that makes a great deal of sense.

    My 'team' (as far as coding goes) is just me which is an advantage in that I don't have anyone else to worry about regarding maintenance, consistency and best practice...it is also a huge disadvantage as I have nobody else to ensure I think about maintenance, consistency and best practice!

    Frameworks are high on my list of things to look into over the festive break...
    ...one of many things thanks to the Wisdom of the Monastry!

      Even your HTML needs some work, a mix of css classes and inline styles. Is it functional, sure. Does it make sense from a maintenance point of view, no. In response to this (and other replies) If what you have works for you and you don't have the time or inclination to learn modern practices nobody has a problem with that, but they way you write code "does nothing to dispel the image of Perl being old fashioned, outdated and obsolete.", and if you keep asking how to improve things you're likely only going to get the same answer you've had before, which has seemingly been dismissed without proper evaluation. At work (and elsewhere) I'm a lone developer frameworks and modern methods help me in my life, you don't need to be in a team to benefit from this. If you were to go down this path I'd suggest familiarising yourself with MVC and the Mojolicious docs, for me this along with just playing around with the thing was the way forwards.

        Can you recommend a "CSS Best Practices"?

        It's common knowledge that HTML is not a "programming" but a "mark-up language", hence it's "trivial".

        But does this apply to "CSS x.0" with all it's layers of OO like multiple inheritance and casual browser incompatibilities?

        (and those JS frameworks manipulating DOM and CSS don't make it easier)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        Even your HTML needs some work, a mix of css classes and inline styles

        The snippet of HTML you refer to was written some 6 years ago, as was mentioned in the post...
        Whilst I cannot say I never add an inline style declaration to an existing class, it is very very rare these days.

        seemingly been dismissed without proper evaluation

        In less than 5 weeks of being here I have adopted strict, got rid of require *.pl; in favour of use *.pm; usage, adopted use FindBin; and use lib; which I previously knew existed but were shielded away in a cloak of mystery, plus numerous other improvements. Not to mention all the stuff I have taken on board about the *nix environment thanks to working with a Raspberry Pi. Change has to be paced!

        Templating certainly has not been dismissed...
        I do get the feeling that Mojolicious may be a step too far as it has the potential to break existing code. I am tending towards Template as a more universal solution that can be incrementally adopted.

        Templating is being evaluated as described in Templating system choice

      > My "team" (as far as coding goes) is just me which is an advantage in that I don't have anyone else to worry about regarding maintenance

      My team are often me, myself and I.

      When working at several projects at the same time one will often have gaps of several weeks in between. All things stored in short memory are wiped out and you start swearing about this "colleague".

      To be fair, I haven't used any template engine yet, because my vice are the dark arts of Perl wizardry (and because web dev is only a part of my endeavors)

      But the community around a framework like Mojolicious is effectively a team giving you support. So I'd certainly chose it for a serious project.

      And by all means, printing HTML line by line makes me speechless. Oo

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11125507]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-28 18:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found