1

In a complex component, there will be a number of /views/viewname/tmpl/default.php (or similar) files. It is quite likely that different views will share common features. Duplicating code is generally a bad thing, to be avoided. What is the best way to share code between different templates? Still allowing for overrides of the shared code?

2 Answers 2

2

Joomla Layouts can be used to share common parts of a View between multiple files. A search and some reading on Layouts will mostly be around how to override the Layouts and from a modifying the template point of view but if you look through some of the core components in the /layout directories you can get an idea of how to use them in the Views of your components.

Some reading to get you going, https://docs.joomla.org/J3.x:Sharing_layouts_across_views_or_extensions_with_JLayout

https://phproberto.com/en/13-jlayout-improvements-for-joomla-3-2

2

Some time ago, I invented a snippet system for my component which lives in the /tmpl/ folder. I can reuse those snippets and users can still override them using plain old template overrides.

Joomla has something which is similar/better: Layouts. I would send you in this direction.

Here are some examples in the Joomla repository: https://github.com/joomla/joomla-cms/tree/4.0-dev/layouts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.