Prestashop and smarty php code - php

I want to include in prestashop (smarty) in the folder "/themes/my_template/modules/my_modul" a php file in the tpl.
example:
<?php
include('/tools/smarty/Smarty.class.php');
$smarty = new Smarty;
$vorname="Horst";
$nachname="Meyer";
$smarty->assign('vorname',$vorname);
$smarty->assign('nachname',$nachname);
// ausgabe
$smarty->display('my_template.tpl');
?>
but the variable {$vorname} is not displayed. what am I doing wrong?

Not sure, that your way will work.
You are working inside templates directory, so you have to create a *.tpl files there.
If you want to include php file, you can use include_php directive inside your template http://www.smarty.net/docs/en/language.function.include.php.tpl
If you want to display an variable inside template, you can use http://www.smarty.net/docs/en/language.function.assign.tpl

Related

How to use module variables in another tpl - product.tpl of my template?

I use the productcomments module, it has in its php file variables $averageTotal and $nbComment, which work in the module's .tpl file.
I would like to use them in the product prodct.tpl file in the main product description.
How can I use these variables? Can they be made with global variables so that they work in all tpl of my site? How to do it?

Include external php inside Wordpress Header

I am trying to do something simple but it won't work.
I have a custom Wordpress header. I need to include external php classes and other stuff. The problem is that if I do that the page breaks, it doesn't work anymore.
This doesn't occur when I try to "require" external php scripts inside page templates. The problem occurs when I include it in the header.
To make it shorter, I have:
header-home.php (standard wordpress theme header file, which has to include the following file)
snippets.php (a php class)
header.home.php is located at /wp-content/themes/twentyseventeen-child/templates...
snippets.php is located at /resources/scripts/snippets.php
Perhaps the header loads something that is not compatible with custom inclusions?
I was able to include an external php file which contains pure html elements. If I try to load custom classes, the page simply breaks. The include filepath is correct, so that's not the problem.
All the files that you are going to require, you must do in the file "functions.php" that is in "/wp-content/themes/twentyseventeen-child/functions.php", then in the file "header.php" you can instantiate your objects or call functions. For example:
Functions.php
<?php
require("./YourClass.php");
function getYourClass() {
$yourClass = new YourClass();
var_dump($yourClass); //Verify if it returns data and then delete this line
return $yourClass;
}
Header.php
getYourClass();//Here it brings the object and shows the output.

Prestashop 1.6 - php into admin override tpl

Just wanted to include a custom php file into an override template I've made but when I use:
{php} include('custom_code.php'); {/php}
or:
{include_php file='../../../../../../panel/update.php'}
The page crashes. Prestashop is so hard to modify.
The approach you are following to include the PHP file is absolutely wrong, you should include the file in the Class file responsible for rendering the TPL file.
Once you do that you can write the business logic in the class file and then pass the required data to TPL file using the following code:
$this->context->smarty->assign('any_var', $any_value);
By using this you can get the data in your Smarty file and use the same accordingly.
I have solved the issue creating a plugin for smarty in the directory /tools/smarty/plugins with the file name function.update_customer.php . then i pute the code in my template .tpl with this shortcode hook {update_customer} .
Hope that helps in the future...

Creating plugin to call mybb header template in Smarty 3

I am working with a Smarty 3 script and I need to call mybb header and footer templates. I normally just create a .php page and put the eval code directly in it but I can't do that with smarty I have to make a plugin. Is it possible to make a plugin that calls templates from mybb?
The normal code to call mybb templates would be like..
<?php
define('IN_MYBB', 1); require "./global.php";
add_breadcrumb("Title here", "somename.php");
eval("\$html = \"".$templates->get("template_name")."\";");
output_page($html);
?>
I have never worked with Smarty let alone making plugins for this?
If you want to assign anything to variable in PHP using Smarty, you could use fetch() method.
For example in PHP:
$html = $smarty->fetch('template.tpl');
In Smarty template file:
This is template.
And after running it, you will have assigned This is template text to $html variable.

wp_head hook including file not working wordpress

I am having some issue with site I am developing. Let me know you some of the pages are static php pages which are working fine. But the issue is with wordpress pages, I have all css and js files are included from header-required.php file. I am calling this header-required.php file from function file by wp_head hook. here is my code of function.php file:
function hook_javascript()
{
include('http://'.$_SERVER['HTTP_HOST'].'/inc/header-required.php');
}
add_action('wp_head','hook_javascript');
And I am calling this function from all wordpress file code wp_head();
here is the code:
while loading, This function is calling properly, but it does not including file header-required.php. If i am including this file from specific wordpress file, Its working.
Please help. Thanks..
your specified path is correct. Actully I am calling this file from wordpress and header-required.php file is php file which is outside wordpress directory. example.com contain all static php pages, and inside this directory,I have created one another directory called wrpas, which contains wordpress. This some what confusing because i am using static php pages and wordpress together on one site. Another thing header and footer files are static php pages, which i am using in wordpres.
Thanks!!!
Put that file in theme folder
Rather than using php include use get_template_part for wordpress
Use
<?php get_template_part('header-required'); ?>
For more details
http://codex.wordpress.org/Function_Reference/get_template_part
Don't include through hook because this is php file, you can directly include through include and require function in your header.php file inside the theme.

Categories