Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

bugfix: boolean logic support in templates


Go to End


3 Posts   1809 Views

Avatar
MattB

Community Member, 7 Posts

29 April 2011 at 3:45am

Edited: 29/04/2011 3:47am

Hi team,

The SSViewer falls over when encountering some AND/OR boolean logic in the template. The PHP generated will break the parser.

This can be fixed in SSViewer::parseTemplateContent():
sapphire/core/SSViewer.php

by changing line 543:
$content = ereg_replace('<' . '% +else_if +([A-Za-z0-9_]+) *\\|\\|? *([A-Za-z0-9_]+) +%' . '>', '<? else_if($item->hasValue("\\1") || $item->hasValue("\\2")) { ?>', $content);

to:
$content = ereg_replace('<' . '% +else_if +([A-Za-z0-9_]+) *\\|\\|? *([A-Za-z0-9_]+) +%' . '>', '<? } else if($item->hasValue("\\1") || $item->hasValue("\\2")) { ?>', $content);

and changing line 547:
$content = ereg_replace('<' . '% +else_if +([A-Za-z0-9_]+) *&&? *([A-Za-z0-9_]+) +%' . '>', '<? else_if($item->hasValue("\\1") && $item->hasValue("\\2")) { ?>', $content);

to:
$content = ereg_replace('<' . '% +else_if +([A-Za-z0-9_]+) *&&? *([A-Za-z0-9_]+) +%' . '>', '<? } else if($item->hasValue("\\1") && $item->hasValue("\\2")) { ?>', $content);

Cheers, Matt

Avatar
Willr

Forum Moderator, 5523 Posts

30 April 2011 at 1:40am

Edited: 30/04/2011 1:42am

Hi Matt,

Could you provide a series of unit test scripts for this or show that it's covered by existing tests. Does your change break any existing tests?

The status of 2.4.x is that it's only really critical or security issues getting through. There may be an intermediate 2.5 release before 3.0 which could include fixes such as this but we would not want to introduce any bugs of course (hence the tests!). SSViewer has been completely overhauled in master so hopefully should already be fine in that!

FYI any changes, bugfixes or other patches should be submitted via github. See http://doc.silverstripe.org/sapphire/en/misc/contributing#sending-pull-requests-for-git for more information.

Avatar
Borgopio

Community Member, 14 Posts

26 July 2011 at 10:13pm

Yep!
It was only a matter of remove the undescore from "else_if" to transform it in the correct PHP's "else if"

Thanks :P