Bug 27334 - Add Template Toolkit support to news items
Summary: Add Template Toolkit support to news items
Status: In Discussion
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Kyle M Hall
QA Contact: Testopia
URL:
Keywords: Manual
Depends on:
Blocks: 26663
  Show dependency treegraph
 
Reported: 2021-01-04 15:29 UTC by Kyle M Hall
Modified: 2022-04-19 13:30 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This patch adds support for using Template Toolkit markup in news items in the same way we can currently use it in slips and notices. For example, a particular part of a news item could be show a different block of text depending on if a certain system preference is enabled or not. It allows supports the use of Koha's TT plugins for data and price formatting and more!
Version(s) released in:


Attachments
Bug 27334: Add Template Toolkit support to news items (1.87 KB, patch)
2021-01-04 15:31 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 27334: Add Template Toolkit support to news items (2.10 KB, patch)
2021-01-19 11:43 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 27334: Add Template Toolkit support to news items (2.15 KB, patch)
2021-01-19 11:59 UTC, PTFS Europe Sandboxes
Details | Diff | Splinter Review
Bug 27334: Add unit test (975 bytes, patch)
2021-02-01 14:14 UTC, Kyle M Hall
Details | Diff | Splinter Review
Bug 27334: Add Template Toolkit support to news items (2.21 KB, patch)
2021-02-07 12:06 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 27334: Add unit test (1016 bytes, patch)
2021-02-07 12:06 UTC, Katrin Fischer
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Kyle M Hall 2021-01-04 15:29:06 UTC
It would be useful if news items could take advantage of template toolkit syntax.
Comment 1 Kyle M Hall 2021-01-04 15:31:46 UTC
Created attachment 114808 [details] [review]
Bug 27334: Add Template Toolkit support to news items

It would be useful if news items could take advantage of template toolkit syntax.

Test Plan:
1) Apply this patch
2) Edit a news item
3) Add some TT to the content like "[% IF 1 %]It works![% END %]"
4) View the rendered news item on mainpage.pl
5) Note the TT is rendered correctly!
Comment 2 Sally 2021-01-19 11:19:24 UTC
This patch won't apply to a sandbox - it gives a series of errors such as:

String found where operator expected at /kohadevbox/koha/C4/NewsChannels.pm line 234, near "croak "ERROR PROCESSING TEMPLATE: ""
	(Do you need to predeclare croak?)
syntax error at /kohadevbox/koha/C4/NewsChannels.pm line 234, near "croak "ERROR PROCESSING TEMPLATE: ""
Compilation failed in require at /kohadevbox/koha/C4/Members.pm line 36.
Comment 3 Kyle M Hall 2021-01-19 11:43:11 UTC
Created attachment 115309 [details] [review]
Bug 27334: Add Template Toolkit support to news items

It would be useful if news items could take advantage of template toolkit syntax.

Test Plan:
1) Apply this patch
2) Edit a news item
3) Add some TT to the content like "[% IF 1 %]It works![% END %]"
4) View the rendered news item on mainpage.pl
5) Note the TT is rendered correctly!
Comment 4 PTFS Europe Sandboxes 2021-01-19 11:59:01 UTC
Created attachment 115310 [details] [review]
Bug 27334: Add Template Toolkit support to news items

It would be useful if news items could take advantage of template toolkit syntax.

Test Plan:
1) Apply this patch
2) Edit a news item
3) Add some TT to the content like "[% IF 1 %]It works![% END %]"
4) View the rendered news item on mainpage.pl
5) Note the TT is rendered correctly!

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>
Comment 5 Sally 2021-01-19 11:59:52 UTC
Works as described - nice addition!
Comment 6 Katrin Fischer 2021-01-31 14:01:30 UTC
It works as described, but as this changes a C4 module we should have some unit tests!

As we are currently working on moving this code to the Koha namespace (bug 22544) adding new features might be a bit bad timing. :)
Comment 7 Kyle M Hall 2021-02-01 14:14:13 UTC
Created attachment 116159 [details] [review]
Bug 27334: Add unit test
Comment 8 Katrin Fischer 2021-02-07 12:06:29 UTC
Created attachment 116467 [details] [review]
Bug 27334: Add Template Toolkit support to news items

It would be useful if news items could take advantage of template toolkit syntax.

Test Plan:
1) Apply this patch
2) Edit a news item
3) Add some TT to the content like "[% IF 1 %]It works![% END %]"
4) View the rendered news item on mainpage.pl
5) Note the TT is rendered correctly!

Signed-off-by: Sally <sally.healey@cheshiresharedservices.gov.uk>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 9 Katrin Fischer 2021-02-07 12:06:32 UTC
Created attachment 116468 [details] [review]
Bug 27334: Add unit test

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 10 Jonathan Druart 2021-02-09 11:02:35 UTC
Please fill the release notes.
Comment 11 Jonathan Druart 2021-02-11 16:02:17 UTC
Kyle, can you detail a bit more the need please?

"It allows supports the use of Koha's TT plugins for data and price formatting and more!"

Which "data"? And what "more"? :)

Seems overkilled for price formatting only.
Comment 12 Kyle M Hall 2021-02-11 20:03:34 UTC
(In reply to Jonathan Druart from comment #11)
> Kyle, can you detail a bit more the need please?
> 
> "It allows supports the use of Koha's TT plugins for data and price
> formatting and more!"
> 
> Which "data"? And what "more"? :)
> 
> Seems overkilled for price formatting only.

Those are just basic examples. A good example would be a news item that shows different information to libraries based on what category they are.
Comment 13 Jonathan Druart 2021-02-12 13:57:57 UTC
(In reply to Kyle M Hall from comment #12)
> (In reply to Jonathan Druart from comment #11)
> > Kyle, can you detail a bit more the need please?
> > 
> > "It allows supports the use of Koha's TT plugins for data and price
> > formatting and more!"
> > 
> > Which "data"? And what "more"? :)
> > 
> > Seems overkilled for price formatting only.
> 
> Those are just basic examples. A good example would be a news item that
> shows different information to libraries based on what category they are.

Logged-in patron's category you mean? How would you do that? We don't pass any variables to ->process.
Comment 14 Kyle M Hall 2021-02-16 11:45:20 UTC
(In reply to Jonathan Druart from comment #13)
> (In reply to Kyle M Hall from comment #12)
> > (In reply to Jonathan Druart from comment #11)
> > > Kyle, can you detail a bit more the need please?
> > > 
> > > "It allows supports the use of Koha's TT plugins for data and price
> > > formatting and more!"
> > > 
> > > Which "data"? And what "more"? :)
> > > 
> > > Seems overkilled for price formatting only.
> > 
> > Those are just basic examples. A good example would be a news item that
> > shows different information to libraries based on what category they are.
> 
> Logged-in patron's category you mean? How would you do that? We don't pass
> any variables to ->process.

My bad, I was thinking the logged in branch code.
Comment 15 Jonathan Druart 2021-02-16 13:20:08 UTC
So you don't need that, you can define several "item news" and set a different library for each of them.
Comment 16 Kyle M Hall 2021-02-17 12:12:51 UTC
(In reply to Jonathan Druart from comment #15)
> So you don't need that, you can define several "item news" and set a
> different library for each of them.

That was just an example. The real power here is combining new with running perl in TT so we have access to any data in Koha. What would make this much better and more convenient is the ability to get a schema object via a TT plugin. That way we can get to the data without resorting to raw perl. What do you think?
Comment 17 Katrin Fischer 2021-02-17 20:39:20 UTC
Hm, wondering... if we could get any object, wouldn't that allow to get around permissions like the ones to access patron data? (might be totally misunderstanding things)
Comment 18 David Cook 2021-02-17 22:11:25 UTC
(In reply to Katrin Fischer from comment #17)
> Hm, wondering... if we could get any object, wouldn't that allow to get
> around permissions like the ones to access patron data? (might be totally
> misunderstanding things)

Yes, it would allow you to get around permissions.
Comment 19 David Cook 2021-02-17 22:12:23 UTC
(In reply to Kyle M Hall from comment #16)
> That was just an example. The real power here is combining new with running
> perl in TT so we have access to any data in Koha. What would make this much
> better and more convenient is the ability to get a schema object via a TT
> plugin. That way we can get to the data without resorting to raw perl. What
> do you think?

This sounds like it might be convenient for a developer but what staff interface user would actually have the knowledge or skill to make use of this?

What's your current/expected use cases? It seems a bit too hypothetical to me at the moment.
Comment 20 Jonathan Druart 2021-04-07 08:49:50 UTC
Still not convinced and there are pending questions.
Setting back to in discussion.
Comment 21 Martin Renvoize 2022-04-19 12:33:43 UTC
Bug 24865 highlights a good use case for this, though I feel we should probably limit the data we allow users to fetch using it similar to the notices..