Jump to:

23481 Posts in 18951 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » The question about Control Construction

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 963 Views
  • NtM
    Avatar
    Community Member
    39 Posts

    The question about Control Construction Link to this post

    I added a new Image field to my template:
    $fields->addFieldToTab("Root.Content.Main", new ImageField("Background_Image_For_Menu"), "Content");

    If the value of the field is not empty, I'm changing background image of the div-block.

    Here is what I', writing in my Page.ss:

    <% if $Background_Image_For_Menu.URL=='' %>
             <div class="row columnsOne submenu" style="background-image:url($Background_Image_For_Menu.URL);">
          <% else %>
             <div class="row columnsOne submenu">
          <% end_if %>

    The construction doesn't work, I'm just getting an empty page.

    Please help! Thank you.

  • Willr
    Avatar
    Forum Moderator
    5503 Posts

    Re: The question about Control Construction Link to this post

    <% if $Background_Image_For_Menu.URL=='' %>

    Couple points - You don't need the $ when your inside <% %>, its = rather then == in the template parser and currently it doesn't support quoting.

    You can simply rewrite that as

    <% if Background_Image_For_Menu %>
    ...
    <% else %>
    ...
    <% end_if %>

    Hope that helps

  • NtM
    Avatar
    Community Member
    39 Posts

    Re: The question about Control Construction Link to this post

    Thank you It helped!

    I have one more question.

    My submenu (Menu(3)) has 8 Items. And according to design I need to show those items in 2 columns,
    so instead
    <ul>
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
    <li>Item5</li>
    <li>Item6</li>
    <li>Item7</li>
    <li>Item8</li>
    </ul>

    I need to have

    <ul>
    <li>Item1</li>
    <li>Item2</li>
    <li>Item3</li>
    <li>Item4</li>
    </ul>
    <ul>
    <li>Item5</li>
    <li>Item6</li>
    <li>Item7</li>
    <li>Item8</li>
    </ul>

    And if there is 10 Items, I need to break menu into 2 columns with 5 Items in each.

    Is there a property to find out a current page number in Menu(level) and an amount pages in the Menu(level)?

    Thank you!

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: The question about Control Construction Link to this post

    I imaging a combination of $Pos and $TotalItems would work for this. See: http://doc.silverstripe.org/doku.php?id=built-in-page-controls#dataobjectset_options

    Something like if Pos > TotalItems/2 then </ul><ul>?

    You might have to write a function in the controller that does the comparison for you though.

  • NtM
    Avatar
    Community Member
    39 Posts

    Re: The question about Control Construction Link to this post

    Thanks!

    I can't write control <% if %> inside another <% if %>? Can I? It doesn't work for some reason

    I'm trying to write like this:

    <% if TotalItems=8 && Pos=5 %>
          </ul>
          <ul>
    <% end_if %>

    doesn't work

    and linke this (doesn't work ether):

    <% if TotalItems=8 %>
    <% if Pos=5 %>
    </ul>
    <ul>
    <% end_if %>
    <% end_if %>

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: The question about Control Construction Link to this post

    Nested if statements are fine.

    Make sure you have a space between '<%' and 'if' same when closing them.

    However, multiple conditions tend to be a problem.

    963 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.