Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Here documents in blocks

by marto (Cardinal)
on Dec 19, 2020 at 16:45 UTC ( [id://11125453]=note: print w/replies, xml ) Need Help??


in reply to Here documents in blocks

"Not very pretty and quite difficult to follow as it becomes more involved, especially as more and more HTML gets added over time. So a slight improvement..."

With respect it isn't 1995 anymore. Using classes and inline styles in HTML? Not using a templating system or modern framework. FWIW Mojolicious has an excellent support for this out of the box.

Replies are listed 'Best First'.
Re^2: Here documents in blocks
by Bod (Parson) on Dec 19, 2020 at 16:52 UTC
    FWIW Mojolicious has an excellent support for this out of the box

    This issue is not limited to delivering webpages...that's just one examples
    There are many other times I find it necessary to print significant blocks of text within an indented block.

      Regardless..., if you're actually writing code like this at all you'd benefit from taking the time learning how not to have to do such things. Separation of data from code is a good first step.

        Separation of data from code is a good first step

        Previously I have attempted to separate an HTML template from the functional code, admittedly not using a pre-built templating system. This was for a system that provides a business overview of KPIs to my senior management team both on demand as a webpage and as an email twice weekly. This code that was produced quite a few years ago is still operational and providing good service.

        Here is an extract from the template file:

        <div style="float:right"> <p class="sectionHead"><b>FHL Properties:</b></p> <table> <tr> <th class="itemHead">Bookings this month:</th> <td>%BOOK_MTH% </td> </tr><tr> <th class="itemHead">Previous 30 days:</th> <td>%BOOK_PREV% </td> </tr><tr> <th class="itemHead">Forthcoming 30 days:</th> <td>%BOOK_30% </td> </tr><tr> <th class="itemHead">Forthcoming 60 days:</th> <td>%BOOK_60% </td> </tr> </table> </div> <hr style="clear:both"> <p class="sectionHead"><b>Progress in Property Event:</b></p> <p class="itemHeadLarge">%EVENT_COUNT% people have registered their in +terest</p> <hr> <p class="sectionHead"><b>Customer Contentment Call List:</b></p> <p class="itemHeadLarge">There are %CALLLIST% people are on the Call L +ist</p> <hr>
        with the %MARKUP% being substituted for the calculated values by the delivery code
        $pulse =~ s/%EMAIL_VIEW_PERCENT%/$empview/g; $pulse =~ s/%EMAIL_CLICK_PERCENT%/$empclick/g; $pulse =~ s/%EMAIL_UNSUB_PERCENT%/$empunsub/g; $pulse =~ s/%SHORTLIST%/$shortlist/g; $pulse =~ s/%CALLLIST%/$calllist/g;
        In practice this is difficult to maintain as there are some 50 items of data to substitute as some KPIs have multiple values and some require pluralisation whilst other don't. From this limited experience quite some time ago, templating seems more trouble than value...or is this not what you mean?

        If there is a way to simplify it which can be quickly implemented then I would certainly change my approach.

        One problem I have faced in the past with this code is that the path to the template file is hard-coded to the production version so I have to remember to change this in the test environment before making changes and swap it back before releasing it back to the wild. It was done this way because the script runs from cron to provide the twice weekly emails. It will be simpler in future because fellow Monks have introduced me to use FindBin; and use lib; that will make this particular application a great deal simpler...perhaps that change alone will revise my experience of HTML templates.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-23 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found