Jump to:

382 Posts in 210 Topics by 196 members

Connect With Other SilverStripe Members

SilverStripe Forums » Connect With Other SilverStripe Members » Writing a IF Loop

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

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

Page: 1
Go to End
Author Topic: 1446 Views
  • anujkryadav
    Avatar
    Community Member
    30 Posts

    Writing a IF Loop Link to this post

    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

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: Writing a IF Loop Link to this post

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

  • anujkryadav
    Avatar
    Community Member
    30 Posts

    Re: Writing a IF Loop Link to this post

    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

  • anujkryadav
    Avatar
    Community Member
    30 Posts

    Re: Writing a IF Loop Link to this post

    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.

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