Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » silverstriping a site with random pictures

Our old forums are still available as a read-only archive.

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

Page: 1 2 3
Go to End
Author Topic: 8660 Views
  • stooni
    Avatar
    Community Member
    89 Posts

    Re: silverstriping a site with random pictures Link to this post

    Hello imback, i bring the image in the sidebar hugh!!!

       
    but i cant render image with the gd i have think i can get these in Sidebar.ss

    <img src="$RandomImage(gallery)" width="$resizeByWidth(150) " alt="$Title photo" />

    it's not working any other ideas!!

    Thanks

    --Stooni

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: silverstriping a site with random pictures Link to this post

    Please have a good look at the tutorials / docs , it explains quite a bit about the Image type.

  • ben123
    Avatar
    Community Member
    4 Posts

    Re: silverstriping a site with random pictures Link to this post

    Hi,

    I'm trying to do this too - I think I've followed through the steps suggested above, but it doesn't seem to be finding the function.

    Have put:

    function RandomImage( $strLeftDirName )
          {
    if ( !is_string( $strLeftDirName ) )
    {
    return false;
    }
    $left_dir = DataObject::get_one("Folder", "Name = \"$strLeftDirName\"");
    $randImg = ( $left_dir->ID ) ? DataObject::get_one("Image", "ParentID = $left_dir->ID", true, "RAND()" ) : false;
    return $randImg->Filename;
    }

       function init() {
          parent::init();
          
          Requirements::themedCSS("style");

       }

    in Page.php, and have put:

    <img src="$RandomImage(assets/Uploads)" />

    in Page.ss.

    I'm just getting:

    <img src="" >

    No error message... what am I missing?

    thanks,

    Ben

  • stooni
    Avatar
    Community Member
    89 Posts

    Re: silverstriping a site with random pictures Link to this post

    Hello i have in the Page.php

    function RandomImage( $strLeftDirName )   
    {
    if ( !is_string( $strLeftDirName ) )
    {
    return false;
    }
        //$strLeftDirName2 = $strLeftDirName."\\_resampled\\";
       $left_dir = DataObject::get_one("Folder", "Name = \"$strLeftDirName\"");
       
    $randImg = ( $left_dir->ID ) ? DataObject::get_one("Image", "ParentID = $left_dir->ID", true, "RAND()" ) : false;
        //resize(25,35);
    return $randImg-> Filename;
    }

    in the function :class Page_Controller extends ContentController !

    and in the Sidebar.ss, at the end!

    <a href="bilder/" ><img src="$RandomImage(foldername)" width="150" alt="$Title photo" /></a></p>

    i hope you can do it ! here the url from the projekt website http://www.nree.ch/

  • ben123
    Avatar
    Community Member
    4 Posts

    Re: silverstriping a site with random pictures Link to this post

    Thanks Stooni.
    Still couldn't work it out!?! - but have gone with a different solution now.

  • JoeJoe
    Avatar
    Community Member
    7 Posts

    Re: silverstriping a site with random pictures Link to this post

    I've also the same problem with creating a thumbnail.

    I use;

    class ProjectHolder_Controller extends Page_Controller {
        function randomProject() {
          $imageField = DataObject::get_one('ProjectPage', "", "", 'RAND()');
          return $imageField;
       }
    }

    And in my Template i use:

    $randomProject.Photo1

    Simply $randomProject.Photo1.SetWidth(100); is not possible. Is there a solution to create a thumbnail ?

    8660 Views
Page: 1 2 3
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.