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.

General Questions /

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

MAYDAY!! Short Code problem heeeelllllllp


Reply


3 Posts   1124 Views

Avatar
Pix

Community Member, 149 Posts

25 November 2011 at 8:34am

Edited: 25/11/2011 8:35am

I am trying to get a form embedded in my page through a short code. It was working just fine and showing up until I tried doing it with a template, and now NO form, but the the other stuff in the template shows up ("Form goes here" text)!

In Page.php:
public static function EmailFormShortCodeHandler($arguments, $content = null, $parser = null) {
    $customise = array();
    $customise['contactme'] = 'test';
    $template = new SSViewer('SendForm');
    return $template->process(new ArrayData($customise));
}

In SendForm.ss:
<% if SendSuccess %>
      <h2>Your Email has been sent!</h2>
   <% else %>
      <h2>Form goes here</h2>
      $HTMLeMailForm
<% end_if %>

The function to generate the form is in Page_Controller, when I called it directly from the short code it showed up, like this:
public static function EmailFormShortCodeHandler($arguments, $content = null, $parser = null) {
$current = Controller::curr();
return $current->HTMLeMailForm()->forTemplate();
}

But I really need to use a template to show the form, any suggestions please heeeeeeeeelllllllp!

Thanks!

Avatar
Ryan M.

Community Member, 309 Posts

26 November 2011 at 6:55pm

A shortcode wouldn't work in a .ss template. If the function HTMLeMailForm is present in your Page file, it should get called with $HTMLeMailField.

Avatar
stallain

Community Member, 61 Posts

28 November 2011 at 2:13pm

@Pix
How about trying this :

static function EmailFormShortCodeHandler(){
$current = Controller::curr();
return $current->renderWith('SendForm');
}