21280 Posts in 5729 Topics by 2600 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 761 Views |
-
The question about Control Construction

7 November 2009 at 8:27am Last edited: 7 November 2009 8:38am
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.
-
Re: The question about Control Construction

7 November 2009 at 9:45am
<% 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
-
Re: The question about Control Construction

7 November 2009 at 10:47am
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!
-
Re: The question about Control Construction

7 November 2009 at 11:09am
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.
-
Re: The question about Control Construction

7 November 2009 at 11:27am Last edited: 7 November 2009 11:36am
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 %> -
Re: The question about Control Construction

7 November 2009 at 12:51pm
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.
| 761 Views | ||
|
Page:
1
|
Go to Top |



