Hi
I've noticed that TemplateFilterModule is being overly greedy since the latest framework update to move to HTML5 type tags
The problem is as follows:
There are 2 types of module tags, open tags and closed tags.
Open tags take the following syntax:
<ktml:modules position="left">
<ktml:modules:content>
</ktml:modules>
and closed tags take this syntax:
<ktml:modules position="left">
Previously, closed tags conformed to the XHML standard with a /> at the end, and thus could be differentiated from open when doing regex replacements.
Now however, the start of the open tag, and the closed tags have the same format, doing a regex replacement becomes harder.
The order in which the tags are replaced has now been swapped, with open tags being replaced first and closed second. The first part of an open tag (<ktml:modules position="left">) is the same as a closed tag (<ktml:modules position="left">), and thus the open tag must be replaced first in order for it not to be misinterpreted as a closed tag. Whilst this does work, there is an issue when using both open and closed tags in the same template.
Take the following example:
In the main template (/applications/site/component/application/view/page/templates/default.php), add the following below the "user4" module tag:
<ktml:modules:content>
</ktml:modules>
thus making:
<div>
<ktml:modules position="user3">
</div>
<ktml:modules position="user4">
<ktml:modules:content>
</ktml:modules>
This is perfectly valid, and the "user4" tag should be replaced first, followed by the user3 tag. However, regex matches from the "user3" tag, through to the closing tag of the "user4":
(place var_dump/breakpoint in TemplateFilterModule line 154:
array(4) {
[0]=>
array(1) {
[0]=>
string(158) "
<ktml:modules position="user3"> |
| </div> |
| <ktml:modules position="user4"> |
| <ktml:modules:content> |
| </ktml:modules> |
"
}
[1]=>
array(1) {
[0]=>
string(5) "user3"
}
[2]=>
array(1) {
[0]=>
string(0) ""
}
[3]=>
array(1) {
[0]=>
string(112) "
</div> |
| <ktml:modules position="user4"> |
| <ktml:modules:content> |
"
}
}
This is not correct. The regex should match only:
<ktml:modules position="user4">
<ktml:modules:content>
</ktml:modules>
However, it's actually matching:
<ktml:modules position="left">
</div>
<ktml:modules position="left">
<ktml:modules:content>
</ktml:modules>
Regex isn't my greatest skill, however I believe it should be possible with some look aheads, and I had partial success with this.
Hope this is helpful.
Oli