-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.2] Add namespace support for templates #30816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Pull Request for Issue #30272. ### Summary of Changes As discussed in the #30272 report, Joomla does not support namespaced templates, this commit solves that. * the `create()` method now checks for namespaced `template` extension types * the `getNamespaces()` method properly recognize *Administrator* and *Site* templates; in addition, it will look for `templateDetails.xml` file instead of `extensionName.xml` and read the designated namespace (Line 182) **Other change** * replaced `defined('_JEXEC') or die;` with `defined('JPATH_PLATFORM') or die;`, perhaps this change was also expected? Either way, it was my best guess. ### Testing Instructions In order to enable namespace for templates, here are the few steps, we'll use the default site template: * open `site/templates/cassiopeia/templateDetails.xml` and add between `<description>` and `<files>` the following ```markup <namespace path="src">Joomla\Template\Cassiopeia</namespace> ``` * delete `site/administrator/cache/autoload_psr4.php` * login to your `site/administrator` * open the newly created `site/administrator/cache/autoload_psr4.php`, the last element of the return object should be ``` 'Joomla\\Template\\Cassiopeia\\Site\\' => [JPATH_SITE . '/templates/cassiopeia/src'] ``` * *optional*: create a custom field in `site/templates/cassiopeia/src/Field` folder and add it to the `templateDetails.xml` along with `addfieldprefix="Joomla\Template\Cassiopeia\Site\Field"` attribute added to the parent `<fieldset>` * *optional* try and call the newly added custom field from your namespaced template into a module/plugin, test it out ### Actual result BEFORE applying this Pull Request The `namespacemap.php` class had no support for Site Templates / Administrator Templates. `addfieldpreffix` couldn't be used with template defined custom fields. ### Expected result AFTER applying this Pull Request Site Templates / Administrator Templates can be developed with namespace features. ### Documentation Changes Required Yes. (I wish I knew where) ### Questions * should I commit this change to the `4.1-dev` branch as well? * should I commit this change to the `staging` branch? If yes, where is the `namespacemap.php` file?
|
This doesn't work well because templates support copy function. |
|
@SharkyKZ what do you suggest? |
|
@SharkyKZ I can confirm, using the template defined custom fields in the options of a plugin doesn't work, so please what do we need to change to make it work? I really think this is important. |
|
This works fine, just not when copying templates. If it doesn't work for you at all, the issue must be elsewhere. |
|
What do you mean "when copying templates" please? You mean multiple template styles? If that's what you mean, I tested that as well, no issue at all. |
|
I mean copying the template using |
|
Well, after a
After correcting the folder structure, (I moved I'm now going forward with testing custom fields defined with modules and see how they work across extensions, I suspect it's going to work the same as for the templates (template defined custom fields don't work in plugin options) given both types have same namespace logic. |
|
Modules don't have the same issue because there's no function for copying module extensions. |
|
Yea, I can confirm, custom fields defined within modules work across extensions. I don't know how to make it work for templates but at this point, I'm happy the template defined fields work inside its back-end panel. I'm now going forward with testing if Obviously we need to document this limitation if this change goes through. |
|
No. This is not acceptable in its current state. Eventually we could remove copy template functionality completely. But until then I suggest to use a plugin for registering template namespaces. |
|
In my view adding a plugin to host libraries, helpers, fields and other resources is just like a template framework, which is not the point I'm trying to make. I was initially a template developer, I used to work with all these frameworks, but after some more experience I came to the point where templates can do anything a framework like T3/T4/Helix can do, and without the troubles of maintenance. I want to avoid bloatware and corruptible code as much as possible, clearly Joomla can & should do without. On the other side, I stand by you. I really hope we implement this feature, I think we can bring back people to Joomla with awesome templates. |
|
@SharkyKZ what is the resolution for this issue? |
|
My opinion hasn't changed since the last comment. |
|
Would be a pity to have Joomla 4 without namespaced templates. |
|
Please who else has a say in this? Is this feature never gonna come to Joomla 4? |
This comment was marked as abuse.
This comment was marked as abuse.
|
I was looking at commit authors and figured you could have a say in it. Thanks for your input. What is more important for Joomla: namespaced templates or copy template functionality? |
|
Well what holds us back merging what is in this PR and check on the copy feature whether that is a namespaced template and than point to documentation how to copy such templates. I would say this would be a fair compromise what does others think? |
Yes that is the reason i suggested to not allow namespaced templates to be copied than via the GUI. So both ways are possible the only disadvantage for namespaced templates is that there is no simple copy feature anymore from the backend for the reasons pointed out here. |
|
Sounds good for me. Imma make a great template without any framework, and you will love it :) |
Copy function could be removed completely. Maybe too late for 4.0. But certainly in 5.0. And templates can already be namespaced, but without using the namespace mapper. |
Why should we not allow using the namespace mapper + add that condition to the copy feature? |
|
I didn't say we shouldn't. Just clearing the misconception that templates can't be namespaced already. |
Ok so this (merging here and add a condition to the copy feature) would be a good way to go forward right? |
|
Back to pending due to merge conflicts after rebase. This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/30816. |
|
@thednp We had to rebase the PR to 4.2-dev, which has caused merge conflicts now. As I can see you have meanwhile deleted the branch for this PR. Does that mean you won't continue this PR and someone else shall take it over? Or are you still available to work on it? In the latter case you would have to restore the patch-2 branch and update it to latest 4.2-dev. We could help with that if necessary. Or you redo the PR with a new branch for 4.2-dev. Just let us know if you continue or someone shall take it over. Thanks in advance. |
|
It's a pity that this didn't make it with the new mode templates... |
|
@richard67 my Joomla PRs, especially the color-picker one, have taken so much of my time I don't even know anymore. @dgrammatiko you referring to child templates? Is this PR crucial for that feature? |
|
@thednp child templates don't depend on the namespaces but it would have been great to have them right from the start fro the new templates that support child templates. It will happen at some point because there's a need for namespaces... |
|
I hope I will have news for you @dgrammatiko soon, I finally found some time and context to learn about custom element slots and I'm planning to release an improved color-picker version to npm (you will also be mentioned), so anyone interested in implementing it in Joomla / Wordpress etc should have a painless transition from what ever color-picker to possibly the best color picker you could ever dream of. As a side note, I wish these improvements would have been implemented into J4.0 already. We're talking small bits of QOL that could make a big difference for our users. Lots of wasted potential. |
|
The only problem which blocks namespaces for templates is the copy function. Right? Can this be removed with child templates? |
The button exists only for Legacy templates because nobody wanted to break B/C in a minor. For the templates that either support child templates or are child templates the button is not available (I've updated my previous comment). Also the idea was to have them only in the new mode, eg the template needs to support child templates to be able to use namespaces (not in this PR, maybe thus the confusion) |
|
@laoneo what I'm trying (probably poorly) to say is that the changes in this PR from the |
|
Partially agree as I would like to see a bootTemplate function which uses the service provider as well. |
|
Ok, where do we disagree? |
No disagree, here I would go one step further. |
Can you explain that step? |
|
To load a template by service provider. |
@laoneo could you write some pseudo code for the provider? I struggle to figure out how the boot process would look like (I mean not for a helper, that would be probably the same as it is for modules but for the entry points like index.php, component.php, etc). Maybe I'm missing the file/folder structure that such templates should follow... |
|
Since the original branch has been deleted I recreated the Pull request and updated it to a more proper version at #39011 I'm closing this for now, thanks |



Pull Request for Issue #30272.
Summary of Changes
As discussed in the #30272 report, Joomla does not support namespaced templates, this commit solves that.
create()method now checks for namespacedtemplateextension typesgetNamespaces()method properly recognize Administrator and Site templates; in addition, it will look fortemplateDetails.xmlfile instead ofextensionName.xmland read the designated namespace (Line 182)Testing Instructions
In order to enable namespace for templates, here are the few steps, we'll use the default site template:
site/templates/cassiopeia/templateDetails.xmland add between<description>and<files>the followingsite/administrator/cache/autoload_psr4.phpsite/administratorsite/administrator/cache/autoload_psr4.php, the last element of the return object should besite/templates/cassiopeia/src/Fieldfolder and add it to thetemplateDetails.xmlalong withaddfieldprefix="Joomla\Template\Cassiopeia\Site\Field"attribute added to the parent<fieldset>Actual result BEFORE applying this Pull Request
The
namespacemap.phpclass had no support for Site Templates / Administrator Templates.addfieldpreffixcouldn't be used with template defined custom fields.Expected result AFTER applying this Pull Request
Site Templates / Administrator Templates can be developed with namespace features.
Documentation Changes Required
Yes. (I wish I knew where)
Questions
4.1-devbranch as well?stagingbranch? If yes, where is thenamespacemap.phpfile?