Skip to content

Conversation

@brianteeman
Copy link
Contributor

@brianteeman brianteeman commented Apr 14, 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.

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
@joomla-cms-bot joomla-cms-bot added Language Change This is for Translators PR-4.0-dev labels Apr 14, 2021
@dgrammatiko
Copy link
Contributor

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

@brianteeman
Copy link
Contributor Author

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

@Fedik
Copy link
Member

Fedik commented Apr 14, 2021

Looks like a good idea

@Fedik
Copy link
Member

Fedik commented Apr 14, 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

@brianteeman
Copy link
Contributor Author

Thanks @Fedik I will test that code

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

@brianteeman
Copy link
Contributor Author

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

@Fedik
Copy link
Member

Fedik commented Apr 14, 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;

@Fedik
Copy link
Member

Fedik commented Apr 14, 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;

@brianteeman
Copy link
Contributor Author

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

@Fedik
Copy link
Member

Fedik commented Apr 17, 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

@Fedik
Copy link
Member

Fedik commented Apr 17, 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 :)

@Fedik
Copy link
Member

Fedik commented Apr 17, 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.

@brianteeman
Copy link
Contributor Author

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

Fedik and others added 2 commits April 19, 2021 08:30
* Clean up double code for content_template_path

* use "default" instead of "none"
@brianteeman
Copy link
Contributor Author

@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

@brianteeman
Copy link
Contributor Author

Resolved conflicts.

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

/>

<field
<field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix indentation.

@Fedik
Copy link
Member

Fedik commented May 1, 2021

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

@Fedik
Copy link
Member

Fedik commented May 3, 2021

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

@brianteeman
Copy link
Contributor Author

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

@Fedik
Copy link
Member

Fedik commented May 3, 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

@brianteeman brianteeman force-pushed the content_templates branch from 6f1234f to 7652e31 Compare May 3, 2021 16:01
@Fedik
Copy link
Member

Fedik commented May 3, 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.

1 similar comment
@alikon
Copy link
Contributor

alikon commented May 3, 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.

@alikon
Copy link
Contributor

alikon commented May 3, 2021

RTC


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label May 3, 2021
@richard67 richard67 added this to the Joomla 4.0 milestone May 5, 2021
@rdeutz rdeutz merged commit d5508ea into joomla:4.0-dev May 7, 2021
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label May 7, 2021
@brianteeman
Copy link
Contributor Author

yay - thank you all!

@brianteeman brianteeman deleted the content_templates branch May 7, 2021 07:28
@PhilETaylor

This comment was marked as abuse.

@brianteeman
Copy link
Contributor Author

care to be more constructive and informative

@PhilETaylor

This comment was marked as abuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Language Change This is for Translators

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants