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.

Customising the CMS

Two hours of searching! Please help!


Reply

6 Posts   758 Views

Avatar
Olly Foster

28 October 2011 at 4:02am Community Member, 3 Posts

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.

Avatar
swaiba

28 October 2011 at 4:20am Forum Moderator, 1796 Posts

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

Avatar
Olly Foster

28 October 2011 at 4:28am Community Member, 3 Posts

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!

Avatar
swaiba

28 October 2011 at 4:38am Forum Moderator, 1796 Posts

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?

Avatar
Howard

29 October 2011 at 11:41am Community Member, 215 Posts

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 [url=http://www.silverstripe.org/form-questions/show/14225#post306687]here[/url]

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

Avatar
Olly Foster

31 October 2011 at 4:56am Community Member, 3 Posts

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