Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » bugfix: boolean logic support in templates

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

Page: 1
Go to End
Author Topic: 961 Views
  • MattB
    Avatar
    Community Member
    7 Posts

    bugfix: boolean logic support in templates Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5503 Posts

    Re: bugfix: boolean logic support in templates Link to this post

    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.

  • Borgopio
    Avatar
    Community Member
    14 Posts

    Re: bugfix: boolean logic support in templates Link to this post

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

    Thanks

    961 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.