Jump to:

23483 Posts in 18976 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Object variables in Shortcode template?

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: 1178 Views
  • purplespider
    Avatar
    Community Member
    81 Posts

    Object variables in Shortcode template? Link to this post

    I have a page which has several "Video" dataobjects related to it..

    I can insert a list of video titles into the page by placing the following in the page template:

    <% control Videos %>
    <p>$VideoTitle</p>
    <% end_control %>

    However, I wish to insert the list using a shortcode, so that it is possible to position the list anywhere within the page content.

    I have setup the shortcode, but the $VideoTitle variable does not appear to work within the shortcode template. Only the <p> tags are pulled in.

    How can I get the $VideoTitle variable to work within the shortcode template?

    (I have simplifed the HTML code for this example, I'm actually inserting a full video thumbnail, title etc, but that's not neccecary for the question).

    Thank you!
    James

  • x75
    Avatar
    Community Member
    42 Posts

    Re: Object variables in Shortcode template? Link to this post

    Hi,

    I know this is old, but if anyone else is looking for a solution check out: ssbits.

    One thing to watch out for: the ShortCodeHandler has to be in the SiteTree and not the Controller...

    Johannes

  • purplespider
    Avatar
    Community Member
    81 Posts

    Re: Object variables in Shortcode template? Link to this post

    Thanks Johannes, that was actually that tutorial I followed to implement the ShortCodes, but I could never get object variables to work inside of the shortcode template, have you managed to get this to work?

  • x75
    Avatar
    Community Member
    42 Posts

    Re: Object variables in Shortcode template? Link to this post

    I'm not quite sure what you mean by object variable.

    If you wan't to use $VideoTitle in your template you need to set it like this:

    ...
    $data = array();
    $data['VideoTitle'] = "What ever";
    ...
    return $template->process(new ArrayData($data));

    Is that what you are looking for?

    Johannes

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