Open jdorn opened 11 years ago
Because of the complexities involved, this will be the solution:
This method will work best with templates that follow the best practice of 3 level templates:
There were some major problems with implementing the above solution. To keep things simple the following rule is used:
This method works best when using 4 levels of templates:
Only the Page elements will use a WYSIWYG editor since they won't contain blocks. This is the part that will change most often anyway. If you want to change the structure of the page or layout, you need to use the source editor.
Here is an example template structure:
page.html.twig
<!doctype html>
<html>
<head>
<title>{% block title %}MySite.com{% endblock %}</title>
{% block javascript %}{% endblock %}
{% block stylesheets %}{% endblock %}
{% block meta %}{% endblock %}
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>
main-layout.html.twig
{% extends "page.html.twig" %}
{% block body %}
<header>
MySite.com
<nav>
<ul>
<li><a href='/'>Home</a></li>
</ul>
</nav>
</header>
<div id='content'>
{% block content %}{% endblock %}
</div>
<footer>
{% include "footer.html.twig" %}
</footer>
{% endblock %}
home.html.twig
{% extends "main-layout.html.twig" %}
{% block content %}
<h1>{% include "home-title.html.twig" %}</h1>
<div class='welcome-message'>
{% include "home-welcome.html.twig" %}
</div>
{% endblock %}
home-welcome.html.twig
<p>Welcome to my site!</p>
Every template except the last one (an example of a page element) will use the Ace editor. Page elements (anything loaded with an "{% include %}" tag will use a WYSIWYG editor.
To keep templates organized, the default directory structure for templates will be as follows:
+ templates
| * page.html.twig
| + layouts
| | * main.html.twig
| + pages
| | * home.html.twig
| + elements
| | + home
| | | * welcome_message.html.twig
DornCMS needs a WYSIWYG editor capable of editing Twig templates. Ideally, any code within Twig tags would show up as plain text in WYSIWYG mode.
The following complexities make this difficult:
Escaping within Twig tags
Twig tags can contain html special characters (like "<" and "&"). These should not be escaped when typed into the WYSIWYG mode
This can probably be fixed with a regular expression replacing all html codes with their unescaped equivalent prior to submitting.
New lines and Twig tags
When an if block is put on it's own line, it should not be wrapped in "
". For example, this would be entered in WYSIWYG mode:When going to source mode, most editors would produce this, which is incorrect.
In some cases though, it is perfectly valid to wrap Twig tags in html. For example:
You can't just do self closing vs. non-self closing since "set" and "extends" should never be wrapped in "
".This is also valid source. How would this show up in WYSIWYG mode?
Possible solutions
As you can see, this also isn't very attractive since it adds a bunch of p tags.