Jump to:

5539 Posts in 1738 Topics by 1224 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Two hours of searching! Please help!

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

Page: 1
Go to End
Author Topic: 743 Views
  • Olly Foster
    Avatar
    Community Member
    3 Posts

    Two hours of searching! Please help! Link to this post

    I am trying to add <% Include ContactForm2 %> at the halfway point in my content. I cannot therefore use a template, however I thought it would be simple enough to edit the source code in the CMS editor. However, the source editor seems to strip the <% %> elements which is extremely frustrating! What is the point in having a source editor when you can't actually edit properly?

    Anyway, I have searched the internet for two hours to try and find a fix and it seems that many people have a similar problems but i can't actually find a solution. As soon as I think im getting warm im presented with a dead link!

    Very frustrating. Can anyone please help?

    I am using ver 2.4.5.

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Two hours of searching! Please help! Link to this post

    Hi Olly,

    Sorry to hear your frustrations, but welcome to the forums!

    The <% %> tags are for the templating laguage that is intended for developer use only as far as I know and should only be editted via a text editor. The TinyMCE within the system is for a CMS user only - I cannot imagine what woes would result in allowing these tags in TinyMCE a user could change upon some code and cause some serious damage to a live system.

    What is you goal here?

    Barry

  • Olly Foster
    Avatar
    Community Member
    3 Posts

    Re: Two hours of searching! Please help! Link to this post

    Thanks for the Swift response Barry.

    I am trying to add a form half way through my page. I have generated the fields in ContactForm2.php, dropped them into a template ContactForm2.ss which is in my includes folder. I want to include this form on my homepage but inbetween some of the content that I have added via the CMS.

    I am the only person that will access the CMS so there is no risk of an end user destroying the page from the inside out. I thought that by simply adding <% Include ContactForm2 %> in the html source editor it should drop my form exactly where i want it. Sadly it wont allow me!

  • swaiba
    Avatar
    Forum Moderator
    1788 Posts

    Re: Two hours of searching! Please help! Link to this post

    Is this with the UserDefinedForm module?

    This is a great module but unfortuanately it can be a bit misleading $UserDefinedForm can be added with the Content throught the CMS and it looks like templating code, but it is not, the code does a straight str_replace to then place the form.

    I hope this helps?

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: Two hours of searching! Please help! Link to this post

    Hi Olly to include your form code in the CMS you can do it one of two ways;
    1 - Setup a shortcode which will allow you to place [contactform] anyway in the tinyMce editor and it will generate your form there,
    2 - Do a string replace (such as the UserDefinedForm module does) to search for a sting such as $ContactForm and then replace it with template code containing the form

    The shortcode method is found here

    The string replace method I use looks like this:

    // Place this in Page.php

       function Content() {
          $Lookup = array(
             '$ContactForm'
          );
          $Replace = array(
             $this->renderWith("ContactForm")
          );
          return str_replace($Lookup, $Replace, $this->Content);
       }

    Then create a ContactForm.ss file that just calls your function:

    $ContactForm

    Does this make sense? Hope it helps,
    Howard

  • Olly Foster
    Avatar
    Community Member
    3 Posts

    Re: Two hours of searching! Please help! Link to this post

    Thank you all for your help. I will try and have a tinker later to night and see if the recommendations above work.

    Regards,

    Olly

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