-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[4.0] Fix tinymce template #33130
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
[4.0] Fix tinymce template #33130
Conversation
TinyMCE has a really powerful feature that almost knows about - the ability to have predefined snippets of text and html. This is not a new feature of TinyMCE it has been present for at least 10 years. The reason no one knows about this or talks about it is that its very hard to use. I am only aware of a blog post by @coolcatcreations explaining how to use it and you will see it is both very powerful but also a pain to setup ## The Problem The folder that tinymce looks in for the stored "templates" is outside of the folder structure that can be accessed within the Joomla adminsitrator ui. In Joomla 4 it is `media/vendor/tinymce/templates` so it can only be accessed by ftp or cli. ## The Solution Change the folder where the "templates" are stored to a user defined folder in the site/templates folder structure. This enables the user to use the template manager to create and edit the "templates". ## Backwards Compatibility No problem here as if a custom folder is not set then the default is the current `media/vendor/tinymce/templates`. The one difference is that the current (and therefore default) behaviour is for the files to be *.html. Because that filetype is by default prohibited in the template manager I have changed it to the supported .txt filetype __only__ when using the custom folder/ ### Bonus A template developer can include predefined snippets of text and html with their template ## To Test Firstly familiarise yourself with this TinyMCE feature. You will find it on the Insert dropdown of the editor toolbar. TinyMCE ships with two examples you can play with. ### Apply the PR Go to the Editor - TinyMCE plugin and there is a new field where you can select the folder to use. Make sure you are in a configuration set that applies to your userlevel (it is probably Set 0) and then select a folder and save. Go to an article and try to insert a template (as you did before) You should get a template not found message Go to the template manager and create two text files in the folder you previously selected - with just plain text - with basic html Now return to the article and you should be able to insert both these templates successfully. ## Issues to solve - need help The list of folders presented to the user to select from was intended to be limited to templates\[template_name]\html\ and all its subfolders but despite my best efforts I was not able to get the folderFilter to includes those subfolders
|
@brianteeman you need the pieces for child templates from #31785 as well here |
|
@dgrammatiko if that gets accepted we can look at that then. |
|
Looks like a good idea |
|
the $templates_dir = $levelParams->get('content_template_path');
$templates_dir = $templates_dir ? '/templates/' . $templates_dir : '/media/vendor/tinymce/templates';
foreach (glob(JPATH_ROOT . $templates_dir . '/*.{html,txt}', GLOB_BRACE) as $filename)
{
...
}
What about |
|
Thanks @Fedik I will test that code I chose txt because its non-executable and the template manager already supports txt files |
|
@Fedik just looking at the if else. How would you deal with |
|
I think with Maybe something like: // Use $name for Template name, and translation constant. Keep original $filename unchanged
$name = pathinfo($filename, PATHINFO_FILENAME);
// Use original $filename
'url' => Uri::root(true) . $content_template . $filename; |
|
Hm, can stay // Use $name for Template name, and translation constant. Keep original $filename unchanged
$name = basename($filename);
// Use original $filename
'url' => Uri::root(true) . $content_template . $filename; |
|
@Fedik I am reluctant to make these changes. The current code works - it can always be refactored at a later date. |
|
hm, I have tested a bit and I noticed that cannot select any other folder than
I have made PR with that changes |
okay, the problem here is that joomla-cms/libraries/src/Filesystem/Folder.php Lines 622 to 624 in f2c2750
that means it will work for: but not for: that complicated :) |
|
As idea, maybe instead of Can be need update description/documentation, so User know where to look. |
|
Thanks for your suggestions they sound good (as does the patch you contributed) I will check this tomorrow as it goes a bit further than I had intended originally |
* Clean up double code for content_template_path * use "default" instead of "none"
|
@Fedik Regarding the path/filter changes |
|
Resolved conflicts. Would be great to get some tests on this. It got really good feedback at joomladayusa |
| /> | ||
|
|
||
| <field | ||
| <field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix indentation.
|
I wanted to test |
|
@brianteeman please check the conflict, |
|
the conflict looked fixed to me locally so I am at a loss as to why it says conflicts now. Any help appreciated |
|
it an indentations, |
6f1234f to
7652e31
Compare
|
I have tested this item ✅ successfully on 7652e31 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33130. |
1 similar comment
|
I have tested this item ✅ successfully on 7652e31 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33130. |
|
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33130. |
|
yay - thank you all! |
This comment was marked as abuse.
This comment was marked as abuse.
|
care to be more constructive and informative |
TinyMCE has a really powerful feature that almost knows about - the ability to have predefined snippets of text and html.
This is not a new feature of TinyMCE it has been present for at least 10 years. The reason no one knows about this or talks about it is that its very hard to use because of a bug in the path that Joomla uses to store the snippets.
I am only aware of a blog post by @coolcat-creations blog post explaining how to use it and you will see it is both very powerful but also a pain to setup
The Problem
The folder that tinymce looks in for the stored "templates" is outside of the folder structure that can be accessed within the Joomla administrator ui. In Joomla 4 it is
media/vendor/tinymce/templatesso it can only be accessed by ftp or cli.The Solution
Change the folder where the "templates" are stored to a user defined folder in the site/templates folder structure. This enables the user to use the template manager to create and edit the "templates".
Backwards Compatibility
No problem here as if a custom folder is not set then the default is the current
media/vendor/tinymce/templates. The one difference is that the current (and therefore default) behaviour is for the files to be *.html. Because that filetype is by default prohibited in the template manager I have changed it to additionally support .txt filetype only when using the custom folder/Bonus
A template developer can include predefined snippets of text and html with their template
To Test
Firstly familiarise yourself with this TinyMCE feature. You will find it on the Insert dropdown of the editor toolbar. TinyMCE ships with two examples you can play with.
Apply the PR
Go to the Editor - TinyMCE plugin and there is a new field where you can select the folder to use.
Make sure you are in a configuration set that applies to your user level (it is probably Set 0) and then select a folder and save.
Go to an article and try to insert a template (as you did before)
You should get a template not found message
Go to the template manager and create two text files in the folder you previously selected
Now return to the article and you should be able to insert both these templates successfully.
## Issues to solve? - need helpThe list of folders presented to the user to select from was intended to be limited to templates[template_name]\html\ and all its subfolders but despite my best efforts I was not able to get the folderFilter to includes those subfoldersBonus!!!!
This is an incredibly marketable feature. (There aren't that many in J4 that the regular user will understand)
Its uses are endless not least the which the ability to build up a complex web page without the bloat and performance issues from a pagebuilder.
Video
As I recorded the talk at joomladay usa which mentions this feature and how to use it I have created a 3 minute video to explain it.