Jump to content
need4speed

[SOLVED] Include a CMS page into the template

Recommended Posts

Is it possible to include the content from one of the CMS pages into my template so I can easily edit it from the administration?

Share this post


Link to post
Share on other sites

Sure, just add code like the following to the PHP file that loads the TPL file:

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



Change 1 to the ID of the CMS page you want to get the content from, then add {$content} in the TPL file where you want the content displayed.

  • Like 4

Share this post


Link to post
Share on other sites

thank you so much for this solution! Now I can have a price-drop page with a custom (via BO) "promotion" content! yeeiii!

Share this post


Link to post
Share on other sites

All the .tpl files is in the themes folder


By the way Rocky can you give me an example how to ride and if, else statement in prestashop?

Eg. if ID = 89 then ...

I hope you can write me an example it could be really useful.

Share this post


Link to post
Share on other sites

In PHP files:

if ($id == 89)
{
  ...
}
else
{
  ...
}



In TPL files:

{if $id == 89}
  ...
{else}
  ...
{/if}

Share this post


Link to post
Share on other sites

Hi i am new on php and in this forum and i have the same problem!
I read the instructions above but i can't find the specific files to edit.
Can you please be more specific on which files i need to edit exactly?
I need to add a new page under terms-and-conditions-of-use for returns & exchange.
Please assist!
Thank you in advance Spyros.

Share this post


Link to post
Share on other sites

I don't understand. Why don't you just edit the "Terms and conditions" page or create a new CMS page? Perhaps I've misunderstood, but it sounds like you want to have two separate CMS pages displayed on the one CMS page.

Share this post


Link to post
Share on other sites

After a better searching on the prestaShop forum i finally found my way to the solution on my problem!
Thank you in advance for your efforts!

It seems that i had to go to Back Office >> Tools >> CMS and click Add new to create my new page and then at Modules edit the module Info block v1.1 by clicking Configure and enable the page i created by selecting the check box.

Thats about all now i can add anything i want!

Spyros.

  • Like 1

Share this post


Link to post
Share on other sites

I've got a related but a bit different question so I'll ask it here: can I make the CMS module display a custom template as one of it's pages instead of pure text?

Share this post


Link to post
Share on other sites

Would you please give thumbnail of how the page will look then?
I am not good in programming & would prefer to see pictures before I make the changes.

Share this post


Link to post
Share on other sites

Sure, just add code like the following to the PHP file that loads the TPL file:<br/><br/>

<br/>$cms = new CMS(1, intval($cookie->id_lang));<br/>if (Validate::isLoadedObject($cms))<br/>   $smarty->assign('content', $cms->content);<br/>

<br/><br/>Change 1 to the ID of the CMS page you want to get the content from, then add {$content} in the TPL file where you want the content displayed.

 

 

I followed this step. But I am not able to do it succesfully in Presta 1.4 .. It is displaying the word Array.. Kindly please help

Share this post


Link to post
Share on other sites

That happens when a language hasn't been specified, so it returns all the languages. The language is being specified in my code above though. Check to make sure $cookie->id_lang isn't returning 0. Perhaps you forgot to add global $cookie; to the top of the function?

Share this post


Link to post
Share on other sites

Hello Rocky,

Thanks for your explanation. I have tested that to add content of a csm page in the footer...

I have added in blockcms.php in line 734 public function hookFooter()

 

like this:

 

 

 

public function hookFooter()

{

global $smarty;

 

if (Configuration::get('FOOTER_BLOCK_ACTIVATION'))

{

$cms = new CMS(7, intval($cookie->id_lang));

if (Validate::isLoadedObject($cms))

 

$cms_titles = self::getCMStitlesFooter();

$smarty->assign(array(

'block' => 0,

'cmslinks' => $cms_titles,

'content' => $cms->content,

'theme_dir' => _PS_THEME_DIR_,

'display_stores_footer' => Configuration::get('PS_STORES_DISPLAY_FOOTER'),

'display_poweredby' => ((int)Configuration::get('FOOTER_POWEREDBY') === 1 || Configuration::get('FOOTER_POWEREDBY') === false)

));

 

return $this->display(__FILE__, 'blockcms.tpl');

}

return '';

}

 

and in blockcms.tpl

 

<div>{$content}</div>

 

But it displays Array

 

What is wrong in my method?

 

Thnak you very much for your help.

Share this post


Link to post
Share on other sites

I am having the same problem with 'Array', am using 1.4, and have tried creating a controller override but it doesn't seem to work.

 

Any clues how to do this for Prestashop 1.4?

 

Thanks!

 

 

 

Hello Rocky,

Thanks for your explanation. I have tested that to add content of a csm page in the footer...

I have added in blockcms.php in line 734 public function hookFooter()

 

like this:

 

 

 

 

 

and in blockcms.tpl

 

 

 

But it displays Array

 

What is wrong in my method?

 

Thnak you very much for your help.

Share this post


Link to post
Share on other sites

So, to do this for 1.4.xx you need to change the blockcms.php file in the blockcms module directory. In my case I needed a CMS text in the footer. To do this find the function "public function hookFooter()" on line747, add the code described in the first post:

 


public function hookFooter()
{
global $smarty;

if (Configuration::get('FOOTER_BLOCK_ACTIVATION'))
{
$cms_titles = self::getCMStitlesFooter();
$smarty->assign(array(
'block' => 0,
'cmslinks' => $cms_titles,
'theme_dir' => _PS_THEME_DIR_,
'display_stores_footer' => Configuration::get('PS_STORES_DISPLAY_FOOTER'),
'display_poweredby' => ((int)Configuration::get('FOOTER_POWEREDBY') === 1 || Configuration::get('FOOTER_POWEREDBY') === false)
));

                      // custom code
                       global $cookie;
                       $cms = new CMS(7, intval($cookie->id_lang));
                       if (Validate::isLoadedObject($cms))
                       $smarty->assign('footercontent', $cms->content);
                      // end custom code


return $this->display(__FILE__, 'blockcms.tpl');
}
return '';
}

 

Where in this line '$cms = new CMS(7, intval($cookie->id_lang));' the number is the ID of the CMS page.

 

Now open the 'blockcms.tpl' file and add the variable wherever you want. In my case it was:

 

<div id="footertext">{$footercontent}</div>

 

Hope this helps for you.

 

greetz,

walter

Share this post


Link to post
Share on other sites

Yes! to make a short explanation: the probleme is lang cookies You need to make $cookies global in the function:

 

global $cookie;

 

LIKE THAT

 

public function hookRightColumn()

{

global $smarty;

global $cookie;

$cms_right = new CMS(8, intval($cookie->id_lang));

if (Validate::isLoadedObject($cms_right))....

Share this post


Link to post
Share on other sites

Please, can anyone tell me how I can make CMS links to go 1st , right before variouslinks. I have pages like "home" and "disclaimer" at the end of the line when they should be at the begining. How can I alter the order?

Share this post


Link to post
Share on other sites

back to the first question for ps 1.5.3.1

 

how to show content of CMS page in tpl page?

 

i would love to have Terms and Conditions CMS page on quick-order and it seems like it would be helpful for many other places

Share this post


Link to post
Share on other sites

I placed the module in the footer and i transferred the same module into all product detail page.

 

now the problem is i want to show different things from the module in footer and different into product details page.

 

just i need the condition like

 

 

if(module hooked into footer){

// code to be executed

}

else{

//remaining code

}

 

can any one help me please!!

Share this post


Link to post
Share on other sites

we could adapt the choice of cms page in a call option feature page with the value No. of cms page?

Share this post


Link to post
Share on other sites

I assigned the display of a feature CMS product, which has the id # 6. for that product in feature I can choisire page posted. But I can not retrieve this value has to bring up the desired CMS.

{foreach from=$features item=feature}
	    {if isset($feature.value)}
   {if {$feature.id_feature|escape:'htmlall':'UTF-8'} == 6}
   {$nbr_page = $feature.value}
   {$my_page->content}
   {/if}
	    {/if}
 {/foreach}

 

and in the productcontroll

$my_page =new CMS($nbr_page,self::$cookie->id_lang);
  self::$smarty->assign('my_page',$my_page);

 

but here it does not work

can you help me ?

Share this post


Link to post
Share on other sites

after correction for variable assignment, it gives it

 

{foreach from=$features item=feature}
{if isset($feature.value)}
{if $feature.id_feature == 6}
{assign var=nbr_page value=$feature.value}
{$my_page->content}
{/if}
{/if}
{/foreach}

 

a thank you to rocky,

 

but here the variable fails to ControllerProduct for CMS generates the page.

 

I was parvien make it appear that saisisant in a variable in the same page (controllerProduct), which does not allow me to recover my information to choose the page (which I selected in the characteristic 6), which provides:

 

$nbr_page = 4;
$my_page =new CMS($nbr_page,self::$cookie->id_lang);
  self::$smarty->assign('my_page',$my_page);

 

someone would have a clue?

Share this post


Link to post
Share on other sites

Sure, just add code like the following to the PHP file that loads the TPL file:

 

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

Change 1 to the ID of the CMS page you want to get the content from, then add {$content} in the TPL file where you want the content displayed.

 

 

This should work for a Front Office:

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

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More