Jump to:

23355 Posts in 17702 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » Diplay DataObject in a popup via ajax?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 2249 Views
  • micahsheets
    Avatar
    Community Member
    164 Posts

    Diplay DataObject in a popup via ajax? Link to this post

    I have a DataObject that contains some HTMLText and possibly a link to a file for download. When a front end user clicks a link I want a popup to show up and display the DataObject via an ss template. I am not sure how to go about this.

    I do know how to make jQuery send an ajax request to a helper Controller that gets the DataObject that the user clicked on. However I don't know how to write the code that will render the DataObject with a template and send the link back to the client computer so that it can open a lightbox or similar with the url of the rendered data. I am not using a PageType for the DataObject.

  • Wolfbane
    Avatar
    Community Member
    5 Posts

    Re: Diplay DataObject in a popup via ajax? Link to this post

    I'm trying to do the exact same thing and I am equally as confused..

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: Diplay DataObject in a popup via ajax? Link to this post

    i am looking for some advice, too. How do implement an template.ss which does not interherit from page but from dataobject class?

    Does anybody know a good tutorial?

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: Diplay DataObject in a popup via ajax? Link to this post

    This may Help http://doc.silverstripe.org/doku.php?id=recipes:ajax_basics

    Essentially you have to tell the object if its called with AJAX to render the data with differently.

    There's a lot of good stuff in the Recipes section, but the Link to them isn't as obvious as it should be
    http://doc.silverstripe.org/doku.php?id=recipes:start

    Also check ssbit.com, it has some really well written tutorials explaining stuff better than some of the documentation

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: Diplay DataObject in a popup via ajax? Link to this post

    Hi Zenmonkey,

    thanks for your reply. I went through the ajax_basics and everything is working fine. But i am not sure where to go from here? I have got ajaxSnippet.ss Template that will be loaded into a <div> in page.ss. But what i need is to open the thickbox and load the ajaxSnippet.ss into the thickbox.

    Link to open thickbox:
    <a href="/silverstripe/ajax.php?refid=$ID&#38;height=381&#38;width=613" class="thickbox" title="$Headline">

    Link to load asynchronisly content into <div>:
    <a href="$URLSegment" onclick="jQuery('#ajaxContent').load('$URLSegment/showImage'); return false;" >

    Can anybody help?

    Greetings, Carsten.

  • zenmonkey
    Avatar
    Community Member
    527 Posts

    Re: Diplay DataObject in a popup via ajax? Link to this post

    I've never used Thickbox. I usually go with FaceBox or ColorBox. But you should just be able to structure your Thick box URL something like:

    <a href="$Link?height=220&width=400" class="thickbox" title="$Headline">$Title</a>

    But I'm not sure how the wrapping controls are structured. You're using $URLSegment which returns the Current Page Segment (ie everything after '/silverstripe/' which isn't the full link. You should be forming the link to point to the Dataobject as if it were a page. Silverstripe will see that the call is an AJAX call and render it accordingly. The only problem I can see is Silverstripe may not like the URL Parameters, so another Model Box Plug-in may be more useful.

    At least thats where I'd start. Right now I'm just using modal boxes to hold login and review forms. I use jQuery to hide the div's, that way if the user has Javascript disabled they can still access the content. I find the solution is simpler. I tend to avoid Ajax calls for SEO reasons, and better degradation.

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