Jump to content

Newb question: Best practice for showing PHP snippets in product.tpl template?


TWDesign

Recommended Posts

Let's say I have this function which I want to output on my product.tpl template

 

<?php
$pageURL = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
echo "<p>The current url is ".$pageURL."</p>";
?>

 

Obviously I can't use the php tags directly within Smarty.

 

I tried replacing the php tags with {php}....stuff here...{/php}

but that didnt work. Everything below those tags didnt render in the browser.

Anyway, it seems like some people say we shouldnt really be using {php}

even for simple php snippets such as this?

 

I'm a bit confused about the "proper" way to include a php snippet like

this into my product.tpl template.

 

Any help please?

Link to comment
Share on other sites

working with any cms requires a good way to find things. For example I use Dreamweaver, so I can easily find who calls what, where things are defined etc as well as live view which rocks. I am sure that there are other editor packages that do similar things but I 'really' like dreamweaver, I use version cs5.

 

So, which ever you choose, you can just simply find xxx.tpl and it will show you who calls it.

Link to comment
Share on other sites

OK. Thanks. But what do you mean by Page Controller? I know there are different Controller files, but how to find the right one?

 

you stated in your first post that you are trying to edit the product.tpl. you might try to find a product controller.

Link to comment
Share on other sites

Does anyone have any advise on this because I feel if I can understand this part, I can do a whole lot more with

PrestaShop.

 

OK, so in the product.tpl file I would simply add this:

 

<p>{$pageURL}</p>

 

And in the ProductController.php file I would need to add the above PHP code.

 

But where? How?

Is there some documentation for this?

 

Any help pls?

Link to comment
Share on other sites

For example I created a new file ProductController.php and added this to the /overrides folder.

 

The new file contains this code:

 

<?php

class ProductController extends ProductControllerCore
{

public function myHelloWorld()
{
	$this->smarty->assign('Hello World', $myOutPut);
}

}

 

then added

 

<p>{$myOutPut}</p>

 

into the product.tpl file.

 

The product page still renders fine

BUT 'Hello World' isn't showing up on the page.

....and yes I have set the Performance preferences to "force compile" and refreshed my browser cache.

 

Using PrestaShop vers 1.4.0 fyi

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