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.

Widgets

Discuss SilverStripe Widgets.

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

Links Widget passing html


Reply

2 Posts   1781 Views

Avatar
sleeper

16 July 2009 at 6:25am Community Member, 6 Posts

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?

Avatar
sleeper

18 July 2009 at 1:30am Community Member, 6 Posts

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.