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.

General Questions

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

The question about Control Construction


Reply

6 Posts   973 Views

Avatar
NtM

7 November 2009 at 8:27am (Last edited: 7 November 2009 8:38am), Community Member, 39 Posts

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.

Avatar
Willr

7 November 2009 at 9:45am Forum Moderator, 5511 Posts

<% 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 :)

Avatar
NtM

7 November 2009 at 10:47am Community Member, 39 Posts

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!

Avatar
Pigeon

7 November 2009 at 11:09am Community Member, 243 Posts

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.

Avatar
NtM

7 November 2009 at 11:27am (Last edited: 7 November 2009 11:36am), Community Member, 39 Posts

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 %>

Avatar
Pigeon

7 November 2009 at 12:51pm Community Member, 243 Posts

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.