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.

Connect With Other SilverStripe Members /

For all SilverStripe-related topics that don't fit into any of the categories above.

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

Writing a IF Loop


Reply


4 Posts   1469 Views

Avatar
anujkryadav

Community Member, 30 Posts

10 December 2009 at 1:56am

Hello
I Want to write a page link in two line for a particular link,I am giving the code in pure php.i need to implement the same code in silverstripe

if($MenuTitle=="Commentating ,& After Dinner Speeches" )
{

$a=explode(',',$MenuTitle);
$MenuTitle=$a[0]."<br/>".$a[1];

}

NOTE:What I am doing is,I am trying to break the link of the page name 'Commentating ,& After Dinner Speeches' into two part, and display the link in navigation as

Commentating
& After Dinner Speeches

Thank you in advance
Please help me out in solving this issue

Avatar
Hamish

Community Member, 712 Posts

10 December 2009 at 8:52am

In your page class, create a method like:

function MultiLineTitle($delimiter = ",") {
   $title = explode($delimiter, $this->MenuTitle);
   foreach($title as $key => $value)
      $title[$key] = Convert::raw2xml($value);
   return implode("<br />", $title);
}

Then in your template:

$MultiLineTitle

If you want to use something other than "," to mark the division between text:

$MultiLineTitle(#)

etc...

Avatar
anujkryadav

Community Member, 30 Posts

11 December 2009 at 7:32pm

Thank you Hamish for your reply and trying to solve my issue,I am new in silverstripe,its only few days since i am using silverstrip,Can you kindly let me know where I will get the page class,it will be very kind of you if you can let me know the page name and its location where i need to add the function.
In the template i know where to add the calling

Avatar
anujkryadav

Community Member, 30 Posts

12 December 2009 at 12:57am

Hello Hamish
As per your instruction I have created the method in page.php and I replaced $MenuTitle with $MultiLineTitle but when I did that none of the menu title appears in the page.I have added a dropdown menu in my website.May be thtat is causing the problem so i am providing you the code of navigation.ss page

Navigation.ss

<!-- [if IE6]><div id="IE6"><![endif]-->
<ul id="menu1">
<% control Menu(1) %>
<% if Children %>
<li class="$LinkingMode"><a href="$Link" class="sub" title="View more info about $Title"><span>$MenuTitle</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<ul class="fly $LinkingMode">
<% control Children %>
<% if Children %>
<li class="$LinkingMode"><a href="$Link" class="fly" title="View more info about $Title"><span>$MenuTitle</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
<!--[if lte IE 6]><table><tr><td><![endif]-->
<ul>
<% control Children %>
<li><a href="$Link" title="View more about $Title" class="$LinkingMode">$MenuTitle</a></li>
<% end_control %>
</ul><!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<% else %>

<li><a href="$Link" title="View more about $Title" class="$LinkingMode">$MenuTitle</a></li>
<% end_if %>
<% end_control %>
</ul>
<!--[if lte IE 6]></td></tr></table></a><![endif]-->
</li>
<% else %>
<li class="$LinkingMode"><a href="$Link" class="top_link" title="View more info about $Title"><span>$MenuTitle</span></a></li>
<% end_if %>
<% end_control %>
</ul>
<!-- [if IE6]></div><![endif]-->

Thank you for taking so much time and helping me.