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...
Related
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?
I can't seem to find any documentation on this so maybe someone here can help. I have been adding all my WooCommerce hooks to my functions.php file but I would rather have all of them in a separate file to keep things tidy. Obviously I will need another php file for these but how do I link it to the functions.php file so that the code runs as it does now? Thanks
just create new file with your woocommerce hooks code name anything what u want.
Ex. woocommercehook.php and place file in theme folder.
in function.php file just include your woocommercehook.php file at last.
include("woocommercehook.php");
Done. all work same as early.
The PHP include/include_once and require/require_once will work fine. However,
create another file with your hooks( woo-hooks.php ) and use WP get_template_directory to require the file.
require get_template_directory() . '/woo-hooks.php';
Is there a way to integrate php instead of twig in Drupal8? Twig looks somewhat annoying. But in drupal 7 we could create tpl files with php syntaxes. Is there any way to create tpl files in Drupal 8 too. I am a beginner for drupal.
this is one of the major and finest change in D8 change template system in twig
in drupal7 no one recommend you to write php code like function or queries or any processing code in theme layer or template file
in drupal 8
HOOK_preprocess_page
and
HOOK_preprocess_node
are available same as in drupal 7
you have to write your code what you want in these fuctions and then send to the template what you want to print
like if you want print current user name in your template then do some thing like this
use HOOK function hook_preprocess_page
if you are writing code in your theme then write this code into your .theme file
if in module then in .module file
function themename_preprocess_page(&$variables) {
global $user;// current user object
$variables['customUserName'] = $user->getUsername();
}
change themename to your theme name if in module then replace with module name
in your twig template you will print this variable like this
{{ customUserName }}
we are overriding page template so your are able to get this variable in all you page templates
if you need this variable in node template then rename function to
function themename_preprocess_node(){}
hope this help you
thanks
I have to override a module view in my custom theme. I copied the tpl I want to override in the right directory but it contains lots of {include file="./[filename].tpl" } and smarty fails with Smarty: Unable to load template. This seems fair, since the files it wants to include are not in my theme override.
Copy dozens of file for a single line cosmetic override seems way too dirty to me.
Is there a way so that I can override a single tpl without have to copy all included files in my theme?
Maybe you could change the paths of the include to where the files actually are:
{include file="$module_dir.[tpl_dir]/[filename].tpl"}
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