Jump to:

794 Posts in 408 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » Links Widget passing html

Discuss SilverStripe Widgets.

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

Page: 1
Go to End
Author Topic: 1767 Views
  • sleeper
    Avatar
    Community Member
    6 Posts

    Links Widget passing html Link to this post

    Hi all,

    Firstly let me just say im getting more and more excited about SS, sure im only trialing it at the moment alongside Modx, but the more i play with it the more i like it and this forum is great for picking up help and advice.

    I want to display an image instead of text (Name field) using the Links Widget (http://silverstripe.org/links-widget/), but it won't pass html, so two questions...

    Is it possible to edit LinkWidget.php so that it will pass html?

    and secondly i wonder if it would be possible to have an image upload option so you can have both an image and a tetx string/name?

  • sleeper
    Avatar
    Community Member
    6 Posts

    Re: Links Widget passing html Link to this post

    I got this to work, not in the prettiest way, but here's what i did in case anyone esle wants to use this to display images rather than text strings.

    LinkWidget.php

    Locate this output section:

    $output_1 = "<li><a href='$link1'>$name1</a><br></li>";
       }
       
       if (empty($test2)){
       $output_2 = "";
       }else{
    $output_2 = "<li> <a href='$link2'>$name2</a><br></li>";
       }

       if (empty($test3)) {
       $output_3 = "";
       } else {
    $output_3 = "<li><a href='$link3'>$name3</a><br></li>";
       }
       
       if (empty($test4)){
       $output_4 = "";
       }else{
    $output_4 = "<li> <a href='$link4'>$name4</a><br></li>";
       }

    change each output line that you wnat to disply an image for like this:

    $output_1 = "<li><a href='$link1'><img src='PATH/TO/IMAGE/$name1' alt='image' /></a><br></li>";
       }
       
       if (empty($test2)){
       $output_2 = "";
       }else{
    $output_2 = "<li> <a href='$link2'>$name2</a><br></li>";
       }

       if (empty($test3)) {
       $output_3 = "";
       } else {
    $output_3 = "<li><a href='$link3'>$name3</a><br></li>";
       }
       
       if (empty($test4)){
       $output_4 = "";
       }else{
    $output_4 = "<li> <a href='$link4'>$name4</a><br></li>";
       }

    Now when you enter the name of the text string in the Links Widget in CMS you enter the image name like this 'myimge.gif'

    I know this is not up there with the cool mods that others here have done, but it may be useful for someone else.

    This works for what i want but ideally i'd lke the option of an image upload so you can have an image diasplyed with alt and title text, it's the image upload that i can't do, but this is a simple workaround.

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