Jump to:

3431 Posts in 1025 Topics by 864 members

Template Questions

SilverStripe Forums » Template Questions » AJAX, renderWith and multiple data sources

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

Page: 1
Go to End
Author Topic: 831 Views
  • SamTheJarvis
    Avatar
    Community Member
    24 Posts

    AJAX, renderWith and multiple data sources Link to this post

    Hi, I've run into a problem on my site: http://ninnle.com/server-browser/

    I've set up a simple bit of AJAX functionality, which requests some gameserver info etc, returns it as ArrayData to an Ajax template.

    However, I want to select an Image DataObject depending on the "map" value from the array of server details...

    I want to do this so I can perform cropping and such on said image.

    Basically I want to send the ArrayData and a DataObject to the template, or merge the two and send. Anybody got any ideas?

    At the moment I'm just putting in the raw image from the filesystem.

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: AJAX, renderWith and multiple data sources Link to this post

    I'm not sure if I fully understand what you're trying to do. But if you're trying perform image transformations based on a URL Parameter you could always extend the Image object and add the functions that pull the URL Param. I usually extend my Image object just to customize default image quality parameter and to embed extra data properties in image tag for jQuery stuff

  • SamTheJarvis
    Avatar
    Community Member
    24 Posts

    Re: AJAX, renderWith and multiple data sources Link to this post

    Ah sorry, I haven't explained myself properly.

    That page has a list of game servers the user can query. Upon clicking that, it sends a request to /ServerDetails/$ID of server in the DB, it then gets the stored IP for this server from the ID. IT then sends a request for a server info, it returns a packet, i decode this, split into an array, wrap in ArrayData and put it in ServerAjax.ss, which is then served to the user. I want to use the "map" array value and get the image dataobject on the server corresponding to this map value (the map that is currently playing on the game server) so I can then manipulate it in the ServerAjax.ss.

    Can I resize in the controller and just add a filename to the ArrayData? Would this mean the requested map image would be manipulated every time the person requested it, or will silverstripe realise there's already a cached image there?

    Thanks

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: AJAX, renderWith and multiple data sources Link to this post

    SilverStripe will cache all resized images in a _resized subfolder placed in the folder that contains the image. If an image exists in the Cache it will serve that one instead of generating a new one. If all you need is the name of the resized image you can do something like this in the template

    <% control Image.SetWidth(250) %>
    $Filename
    <% end_control %>


    $Filename returns the relative path of image ie "assets/Uploads/.../filename.jpg"

    you can also do this in the PHP by performing the manipulation on your image object and returning $image->Filename (you may need to call cacheFilename, I've never needed to call do it that way http://api.silverstripe.org/2.4/sapphire/filesystem/Image.html

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