? ? ? Pending

User tests: Successful: Unsuccessful:

avatar brianteeman
brianteeman
14 Apr 2021

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/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 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

    • 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

Bonus!!!!

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.

avatar brianteeman brianteeman - open - 14 Apr 2021
avatar brianteeman brianteeman - change - 14 Apr 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 14 Apr 2021
Category Administration Language & Strings Front End Plugins
d1496f2 14 Apr 2021 avatar brianteeman cs
avatar brianteeman brianteeman - change - 14 Apr 2021
Labels Added: ? ?
avatar dgrammatiko
dgrammatiko - comment - 14 Apr 2021

@brianteeman you need the pieces for child templates from #31785 as well here

avatar brianteeman
brianteeman - comment - 14 Apr 2021

@dgrammatiko if that gets accepted we can look at that then.

avatar Fedik
Fedik - comment - 14 Apr 2021

Looks like a good idea

avatar Fedik
Fedik - comment - 14 Apr 2021

the if/else block can be eliminated :

$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)
{
  ...
}

I have changed it to the supported .txt filetype

What about .tmpl? some editors have a code highlight for this file type. With .txt can be hard.
but this need to test

avatar brianteeman
brianteeman - comment - 14 Apr 2021

Thanks @Fedik I will test that code

I chose txt because its non-executable and the template manager already supports txt files

9cacc02 14 Apr 2021 avatar brianteeman alpha
avatar brianteeman
brianteeman - comment - 14 Apr 2021

@Fedik just looking at the if else. How would you deal with
$filename = basename($filename, '.txt');
'url' => Uri::root(true) . $content_template . $filename . '.txt',

avatar Fedik
Fedik - comment - 14 Apr 2021

I think with pathinfo https://www.php.net/manual/en/function.pathinfo.php

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;
avatar Fedik
Fedik - comment - 14 Apr 2021

Hm, can stay basename() with same logic:

// 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;
avatar brianteeman
brianteeman - comment - 14 Apr 2021

@Fedik I am reluctant to make these changes. The current code works - it can always be refactored at a later date.

avatar Fedik
Fedik - comment - 17 Apr 2021

hm, I have tested a bit and I noticed that cannot select any other folder than cassiopeia/html.
It does not looks right.

I am reluctant to make these changes

I have made PR with that changes

avatar Fedik
Fedik - comment - 17 Apr 2021

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

okay, the problem here is that folderFilter="^html" looking for single folder name, not for full path

if (($isDir xor $findFiles) && preg_match("/$filter/", $file))
{

that means it will work for:

html/
html_foo/
htmlbla/

but not for:

html/foo/
html/bla/

that complicated :)

avatar Fedik
Fedik - comment - 17 Apr 2021

As idea, maybe instead of folderFilter="^html" make folderFilter="^tinymce",
and create an empty folder in cassiopeia/html/tinymce

Can be need update description/documentation, so User know where to look.

avatar brianteeman
brianteeman - comment - 17 Apr 2021

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

avatar brianteeman
brianteeman - comment - 19 Apr 2021

@Fedik Regarding the path/filter changes
with the option recursive=true and the folderFilter I had assumed that they would work together for the desired result but clearly they don't

avatar brianteeman brianteeman - change - 19 Apr 2021
The description was changed
avatar brianteeman brianteeman - edited - 19 Apr 2021
avatar joomla-cms-bot joomla-cms-bot - change - 19 Apr 2021
Category Administration Language & Strings Front End Plugins Administration Language & Strings Front End Plugins Templates (site)
ce34944 19 Apr 2021 avatar brianteeman html
avatar brianteeman brianteeman - change - 19 Apr 2021
The description was changed
avatar brianteeman brianteeman - edited - 19 Apr 2021
avatar brianteeman
brianteeman - comment - 30 Apr 2021

Resolved conflicts.

Would be great to get some tests on this. It got really good feedback at joomladayusa

avatar Fedik
Fedik - comment - 1 May 2021

I wanted to test
But found that the man with name @brianteeman broke this PR with #33177 😄

avatar brianteeman brianteeman - change - 3 May 2021
The description was changed
avatar brianteeman brianteeman - edited - 3 May 2021
avatar Fedik
Fedik - comment - 3 May 2021

@brianteeman please check the conflict,
the options is fixed in #33464, but it made a conflict with your changes

avatar brianteeman
brianteeman - comment - 3 May 2021

the conflict looked fixed to me locally so I am at a loss as to why it says conflicts now. Any help appreciated

avatar Fedik
Fedik - comment - 3 May 2021

it an indentations,
try like next: copy setoptions.xml from 4.0-dev branch, and re-add "content_template_path" field.
this will be easiest way

avatar Fedik Fedik - test_item - 3 May 2021 - Tested successfully
avatar Fedik
Fedik - comment - 3 May 2021

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.

avatar alikon alikon - test_item - 3 May 2021 - Tested successfully
avatar alikon
alikon - comment - 3 May 2021

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.

avatar alikon alikon - change - 3 May 2021
Status Pending Ready to Commit
avatar alikon
alikon - comment - 3 May 2021

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33130.

avatar rdeutz rdeutz - change - 7 May 2021
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2021-05-07 07:27:28
Closed_By rdeutz
Labels Added: ?
avatar rdeutz rdeutz - close - 7 May 2021
avatar rdeutz rdeutz - merge - 7 May 2021
avatar brianteeman
brianteeman - comment - 7 May 2021

yay - thank you all!

avatar PhilETaylor
PhilETaylor - comment - 11 May 2021

this broke stuff.

avatar brianteeman
brianteeman - comment - 11 May 2021

care to be more constructive and informative

avatar PhilETaylor
PhilETaylor - comment - 11 May 2021

Care to be more patient while I actually type?? I was copy and pasting.

PR to revert is here #33804 and the issue is #33783

Add a Comment

Login with GitHub to post a comment