Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Ordering Template cards

by 1nickt (Canon)
on Jan 24, 2021 at 16:46 UTC ( [id://11127371]=note: print w/replies, xml ) Need Help??


in reply to Ordering Template cards

Hi,

"Should I be calling multiple template files from the script or should that processing be done within Template?"

Seems to me from what you've shown that for each rendering of the page, you will have an array of cards that you have pulled from the DB for the given user. If that's the case then I would use a [% FOREACH card IN cards %] ... [% END %] block in the template and just show 'em in the order given. See http://www.template-toolkit.org/docs/manual/Directives.html#section_Loop_Processing.

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Ordering Template cards
by Bod (Parson) on Jan 24, 2021 at 16:52 UTC
    I would use a [% FOREACH card IN cards %] ... [% END %] block in the template and just show 'em in the order given

    I do exactly that when each card is a similar layout and it's really just a case of substituting in values. But here, every card is totally different. Some have tables, others just a heading a line of text whereas others have a graph. Hence why I was thinking of a separate template file for each card.

      If the cards are that different, I would keep them as separate files. This will make it easier to make changes to limited parts of the cards, and will maybe even encourage you to copy a template file for a slightly (but enough) different new card.

      As switching to a different card means a reload (I guess), keeping the different cards as different templates makes sense.

        If the cards are that different, I would keep them as separate files.

        In most cases, there is no similarity between them other than colours, font sizes and fonts.

        As switching to a different card means a reload (I guess)

        The cards are all displayed at the same time. One after the next. The current system is designed to be viewed on mobile and has a very constrained width on desktop so they appear one below the previous one. The refactored version may make use of the width of a desktop and display the cards in columns but, as they are all different heights, that won't be trivial.

      Hm, so maybe the card hash in the array cards has a field card.data and a field card.template, and then inside the loop you process the template with the data using INCLUDE? You can reference data in variables using a sigil in nested directives for this.

      Hope this helps!


      The way forward always starts with a minimal test.

        Something along these lines...

        [% templatefile = card.template %] [% INCLUDE "$templatefile" %]
        Thanks - I will test doing something along those lines

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 13:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found