Jump to content

[SOLVED] Include a CMS page into the template


Recommended Posts

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
Link to comment
Share on other sites

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

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.

Link to comment
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
Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...

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

Link to comment
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?

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

  • 1 month later...

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.

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

  • 1 month later...

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

Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...
  • 3 weeks later...

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!!

Link to comment
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 ?

Link to comment
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?

Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...

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);
Link to comment
Share on other sites

  • 4 months later...
×
×
  • Create New...