Is there a safe way to make a change to code in a core Grav Module, so it won’t be overridden next time I update grav?
A case in point right now is that the page summary hard truncates at the summary size set in the Admin panel with ellipsis. I would rather that it truncated on word boundary. A quick look through the code reveals that the summary is generated in
Actually got stuck in a whole ‘nother set of config and forgot to add my unsafe little tweak in the core to the to-do list, so thanks for the reminder.
Yes, the twig filter does what it says on the tin, and so solves the specific use case.
where page.header.exclude summary is a variable I added to the defaults.yaml blueprint so that posts could have a teaser summary, different from the body content.
I’m assuming that the broader question of how best to change core code the answer is probably “don’t”, but it does look like plugins are the easiest solution. I’m used to an environment where the norm was inherit and override
I think the answer is more like “you’re probably doing it wrong” and you likely realise now that a better title would have addressed the specific question rather than gone broader. But these are easy beginner fumbles!
You gotta be careful with your words around here I think that is the norm.
As the others suggest, the safest and most resilient way is utilizing a plugin to add rather than change functionality. That doesn’t, however, mean it cannot be done. Grav is a package that follows PSR-4 in autoloading dependencies. That also means you can override classes like you normally would with a library loaded through Composer, fairly straightforwardly through the psr-4 and/or files properties.
For the specific use-case your theme or plugin could more easily supply a different Twig function or filter to do the truncation. Many themes and plugins does this, and there’s a dedicated entry in the cookbook for how: Custom Twig Filter/Function.