Jump to content

[TUTORIAL PS 1.6] Adding CMS content to the Contact Page


dpcdpc11

Recommended Posts

In this tutorial I'll show you how to fix one of the features missing in PS.

 

The problem:

Every time I develop an online store, at some point the client wants a custom Contact page that they can easily edit whether they need to change the address or add a new phone number or edit the business hours. Unfortunately PS doesn't come with such an option out of the box which I personally find pretty weird!

 

The solution:

Adding in the contact-form.tpl the content of a CMS Page which can easily be edited in the back office.

 

Steps:

- create a CMS Page in the back office and fill it with everything you want to be displayed on the Contact page

- write down the page ID (for example: 5)

- override the ContactController, mainly overriding the initContent() function.

- to override the ContactController create a new file called ContactController.php and copy it to root\override\controllers\front\

- paste the code from the attached file in the new ContactController.php:

 

- as you can see, just before:

$this->setTemplate(_PS_THEME_DIR_.'contact-form.tpl');
I've added:
global $cookie;$cms = new CMS(5, intval($cookie->id_lang));if (Validate::isLoadedObject($cms))$this->context->smarty->assign('content', $cms->content);
where the 5 is the ID of the CMS Page created in the Back Office.

- now go in your theme folder and edit contact-form.tpl by adding

{$content}
where ever you want the CMS's page content to show up.

- if you want to split the Contact content in half then I suggest something like this:

<div class="contact_page_left">{$content}</div><div class="contact_page_right">the whole code related to the contact form</div>
- then style the 2 css classes however you like.

 

I hope this helps!

 

CREDITS: goes out to rocky of course, the PS Legend for pointing out the solution here: https://www.prestashop.com/forums/topic/79566-solved-include-a-cms-page-into-the-template/?p=446547

contactController.php

Edited by dpcdpc11 (see edit history)
  • Like 9
Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

(...)

- paste the following code in the new ContactController.php:

CODE

- as you can see, just before:

$this->setTemplate(_PS_THEME_DIR_.'contact-form.tpl');

I've added:

global $cookie;
$cms = new CMS(5, intval($cookie->id_lang));
if (Validate::isLoadedObject($cms))
$this->context->smarty->assign('content', $cms->content);

where the 5 is the ID of the CMS Page created in the Back Office.(...)

 

 

Hmm, can you please paste all the code again? Its quite not visible, thanks.

Edited by koyocik (see edit history)
Link to comment
Share on other sites

  • 2 months later...

Just what I was looking for! but @koyocik is right, where's the code?

I've edited the first post. For some reason the original code was removed. Maybe it was too much code... Dunno. Use the php file attached to the first post and let me know if it works. Btw are you Romanian? You're username looks familiar.

Edited by dpcdpc11 (see edit history)
Link to comment
Share on other sites

I've edited the first post. For some reason the original code was removed. Maybe it was too much code... Dunno. Use the php file attached to the first post and let me know if it works. Btw are you Romanian? You're username looks familiar.

Great! thanks for sharing. And not, I'm spanish ;)

Link to comment
Share on other sites

That's why I explained what I did so people could take the principle and adapt it to their needs. If you know a bit about prestashop than you should know how to overwrite a core controller and add the code I mentioned above, that starts with global $cookie etc.

Do some thinking my friend and try to figure out what to do. It's not hard since I've explained the logic.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Hi,

 

I need some help..

 

i have followed your instructions, I am using Prestashop 1.6.1.3, and very new to this coding..

 

I went to public_html -> controllers -> front -> ContactController.php and added:

global $cookie;
$cms = new CMS(6, intval($cookie->id_lang));
if (Validate::isLoadedObject($cms))
$this->context->smarty->assign('content', $cms->content);

 

and then to  public_html ->themes -> defaultbootstrap->ContactForm.tpl and added:

{$content}

 

When i go to contacts page, only the contact form shows no sign of cms page.

 

Do I need to add anything else in {$Content}?

Am i adding the codes in the right file?

 

I do apologize in advance for the trouble but if you have the time can you please help me?

Link to comment
Share on other sites

  • 1 month later...

Works for 1.6.1.4

 

dpcdpc11, you are a hero! Thanks for this wonderful guide!

yaniv14, you are a hero too for adding that last hint!!!

 

NielsTy,

 

did you follow dpcdpc11's instuctions to the letter or did you have to change anything for it to work in 1.6.1.4?

 

I have followed the instuctions, but when I put contactcontroller.php in the overrides folder, my contact page is completely blank.

 

I saw dpcdpc11's comment that it might need to be changed, but alas, this is beyond me.

 

I consider this to be a very interesting hack, and I would love to use it, but no joy so far...

 

Regards,

Dave.

Link to comment
Share on other sites

  • 2 weeks later...

Hi all,

 

- I pasted dpcdpc11 's code into /overides/controllers/front and made the change necessary, i.e. changed 5 to 22, as this is the index of my cms page.

- I then added {content} to the contact-form.tpl in my themes folder

- I deleted class-index.php from the cache folder.

 

but... when I now go to look at the contact page (where the form is located) All I get is a blank screen.

Is it possible that I am putting {content} in the wrong place in the contact-form.tpl??

 

Any help appreciated

 

Dave.

Link to comment
Share on other sites

I put that in the top of the contact-form.tpl, right after </h1>:

{capture name=path}{l s='Contact'}{/capture}
<h1 class="page-heading bottom-indent">
    {l s='Customer service'} - {if isset($customerThread) && $customerThread}{l s='Your reply'}{else}{l s='Contact us'}{/if}
</h1>
{$content}

Edited by NielsTy (see edit history)
Link to comment
Share on other sites

Niels,

 

I was just looking at the two files when your reply came in. I see that they are indeed very different (the default theme contactcontroller.php) and the one dpcdpc11 posted.

 

I wouldn't have a clue as to where to start looking to modify the current one to include dpcdpc11's modifications.

 

Regards,

and thanks for your input,

Dave.

Link to comment
Share on other sites

As you also uses PS 1.6.1.4, i guess you can use the file I have... however, i have no clue how to attach a file here :wacko:

Do you know?

You can also send me your email address in private message, and i will send you ContactController.php

 

Niels

Link to comment
Share on other sites

  • 3 weeks later...
Guest locen

Hi, I have problems when i add image in cms page. i can't add image by click 

post-1119372-0-71241900-1459406351_thumb.png

but i should follow these passages  to insert images. 

post-1119372-0-58574700-1459406387_thumb.png

can someone help me? 

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...
  • 1 month later...
  • 2 months later...

- I pasted dpcdpc11 's code into /overides/controllers/front and made the change necessary, i.e. changed 5 to 22, as this is the index of my cms page.


- I then added {content} to the contact-form.tpl in my themes folder


- I deleted class-index.php from the cache folder.


 


Did exactly the same as this user although my cms content does not load on the contact page.


 


Any ideas?

Link to comment
Share on other sites

  • 2 months later...
  • 5 months later...
  • 4 months later...

Overriding whole core controllers may cause many problems. It should only override specific actions. Here's much simpler and much safer solution:

1. File /override/controllers/front/ContactController.php should have this content only :

<?php

class ContactController extends ContactControllerCore
{
   public function initContent()
   {
      parent::initContent();
 
      $this->context->smarty->assign(array(
         'cms' => CMS::getCMSContent('7', $this->context->language->id), // where 7 is ID of CMS page
      ));
   }
}

2. In /themes/<your_theme>/contact-form.tpl add wherever you want your cms content:

<div class="rte">{$cms.content}</div>

 

Link to comment
Share on other sites

  • 3 months later...

My previous solution works in every other page, but stopped working with ContactController.php on presta 1.6.1.18. It works if I add

'cms' => CMS::getCMSContent('7', $this->context->language->id)

directly in /controllers/front/ContactController.php. It looks like overriding of this controller is impossible now. Can anyone confirm or have a fix for this?

 

E: The solution is to force compilation and clear cache once

Edited by Sharak (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...