Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » if and else_if with InSection()

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

Page: 1 2 3
Go to End
Author Topic: 10750 Views
  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: if and else_if with InSection() Link to this post

    Decided to test straight away and had issues both with the latest SVN build of SS, and the patch. Decided to post here rather bog up the Trac entry in case I was doing something wrong.

    Steps to duplicate errors:

    1. Get latest SVN from http://svn.silverstripe.com/open/phpinstaller/trunk
    2. Install SS as normal using Blackcandy Theme
    3. Add following code to /themes/blackcandy/templates/Page.ss just above $Layout

    <% if InSection(home) %>
    Home
    <% else_if InSection(about-us) %>
    About Us
    <% else %>
    Not Home or About Us
    <% end_if %>


    4. Check out the home page and about us page on new installation.

    ERRORS on SS Trunk
    1. When on home page, not only is "Home" displayed by the above code, but the <% else_if InSection(about-us) %> statement is not parsed and "Home <% else_if InSection(about-us) %> About Us" is displayed on the page.

    2. When on about-us page, only "Not Home or About Us" is displayed.

    The Patch
    1. Apply patch with Tortoise SVN (Windows XP). /sapphire/core/SSViewer.php, /sapphire/tests/SSViewerTest.php and /cms/templates/Includes/CommentAdmin_SiteTree.ss all updated.
    2. Go to home page and flush=1

    ERROR on Patch
    Fatal error: Class 'TemplateParser' not found in C:\wamp\www\ss_latest\sapphire\core\SSViewer.php on line 405

    I havn't had time to go through the code to figure that out yet.

    Cheers
    Aaron

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: if and else_if with InSection() Link to this post

    Aaron,

    My bad. I forgot to include the template parser file in that patch file. Patch file revision 5 has been revised to include that file!

    Does it work any better now?

    Ben

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: if and else_if with InSection() Link to this post

    No more fatal error. But there is a SS error there:

    http://sandbox.ecomgroup.co.nz/aaron_ss/SS_TemplateParserStackTrace.htm (not live, just an HTML dump)

    Occurs with or without the test template block in my previous post.

    A little over my head without picking through the code and working out how this exactly works.

    Cheers
    Aaron

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: if and else_if with InSection() Link to this post

    Aaron,

    This is valuable feedback. I think the problem is that my PHP install has a later version of the PCRE (Perl Compatible Regular Expressions) library which supports \g<name> syntax. I probably need to rework the expressions to not use that feature.

    Would you be able to provide a copy of your server's phpinfo() output (at least the PHP version & PCRE info parts)? With that info, maybe I can find a matching PHP build for me to test on.

    Thanks,
    Ben

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: if and else_if with InSection() Link to this post

    In the mean time, I posted revision 5.1 which uses a different syntax style in the regular expressions. Maybe it will work on your PHP install.

    Details:
    Revision 5 used Oniguruma style subroutine calls; 5.1 uses Python's style.

    Ben

  • Double-A-Ron
    Avatar
    Community Member
    599 Posts

    Re: if and else_if with InSection() Link to this post

    Hi Ben,

    No luck there sorry. 5.1 fails to parse pretty much everything and just pumps out all the <% %> tags to browser.

    I am using WAMP 2.0 on Windows XP.

    http://sandbox.ecomgroup.co.nz/aaron_ss/phpinfo.htm

    Cheers
    Aaron

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: if and else_if with InSection() Link to this post

    Hi Aaron,

    This is strange. To verify that the patch contains all of the necessary files, I just applied it to a fresh copy of truck. The patch worked flawlessly. Would you have time where we could hope on IRC together and troubleshoot this?

    Ben

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: if and else_if with InSection() Link to this post

    *Sigh* This still isn't fixed?

    Just ran into this issue on a site I'm working on. Seems like a pretty common request and could be useful.

    I was the one that originally brought this up when I stumbled across it in SS version 2.2.x

    I would have thought/hoped this would be fixed now that we're coming up to 2.4 Any word on this? I see the ticket is still unassigned in trac.

    10750 Views
Page: 1 2 3
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.