How to change the content of Variables called in Template file of Prestashop - smarty

banners.tpl files code snippet
{if !empty($banner.html)}
<div class="custom-html">
{$banner.html nofilter}{* can not be escaped *}
</div>
{/if}
How can I change the content of $banner.html variable?

You have to find the .php file whose display banners.tpl
then, analyse variables are assign to smarty and change it !

Related

How to STR Replace and echo in laravel

Files that are uploaded to my site have their names changed and extention change to bin. So for example a uploaded file will be dfd84848.bin, using the bin file worked fine with modelviewer but im trying to test babylon.js and it doesnt work with .bin only if i change .bin to .glb.
This code {{uploaded_asset($detailedProduct->cad_file)}} provides link like uploads/all/p1YZX9TBc7EmimFx4rXnSFKvVor8EttpOUUpylLL.bin
I want to change .bin to .glb and echo it.
i tried this
#php
$previewfile = uploaded_asset($detailedProduct->cad_file);
$replaced = Str::replace('.bin', '.glb', $previewfile );
#endphp
to show i used this <model url="{$replaced}"> but it never echoed url
Edit
So now that it echos as name.glb it doesnt work because the file doesnt exist on server. When 3d models such as .glb, .gltf are uploaded they are renamed to .bin i dont know why. The uploader is AizUploadController.php
To echo a value you should use double curly braces:
<model url="{{ $replaced }}">
Docs: https://laravel.com/docs/8.x/blade#displaying-data

Blade templating

Is it possible to have the master.blade.php file outside of the template files.
Example below:
views/
master.blade.php
layout/
hello.blade.php
views/layout/hello.blade.php
#extends('layout.master)
I have tried the above but it cannot find the master.blade.php file. So is there a way to refer to a directory above the blade file.
it would be
#extends('master')
the "." in the view names indicate folders. so
#extends('my.long.path.to.template')
would be found in:
/views/my/long/path/to/template.blade.php
layouts don't have to be in a folder called layouts

Include other .tpl in a .tpl file Prestashop

I'm usinh a Prestashop 1.5.4.1, and I would like to call a module in other module (precisely I need to use slider module just above the home featured products). I tried to call it via
include file='../directory/module.tpl'
but always I get only blank page without any code. I also tried with different ways of directory statement, but always the result was the same. Is there any possibility to include new module in correct way?
For this to work, your directory structure should be (Using PrestaShop 1.6):
-- mymodule.php
-- views
---- templates
------ hook
------ displayFooBarTemplate.tpl
-------- inc
---------- foo.tpl
---------- bar.tpl
Absolute way:
From your main module file:
protected function displayFooBarTemplate()
{
global $smarty;
...
$smarty->assign('module_templates', dirname(__FILE__).'/views/templates/');
return $this->display(__FILE__, 'displayFooBarTemplate.tpl');
}
then in your tpl file (displayFooBarTemplate.tpl):
{include file="{$module_templates}hook/inc/modal/foo.tpl"}
{include file="{$module_templates}hook/inc/modal/bar.tpl"}
Relative way (my favorite):
{include './inc/foo.tpl'}
{include './inc/modal/bar.tpl'}
What worked for me in Prestashop 1.6 is
{include file="$tpl_dir/modules/blocknewsletter/blocknewsletter.tpl"}
I put this in the footer.tpl file and correctly displayed the text box for subscribing to the newsletter. I suppose it works for all other modules, too.
Proper way to include a smarty tag includes using the curl brackets.
{include file='directory/module.tpl'}
Note that the directory in the include statement should be relative to the templates directory.
http://www.smarty.net/docsv2/en/language.function.include.tpl
In your php code declare a variable like this :
$this->path_to_tpl_folder = str_replace('\\', '/', _PS_MODULE_DIR_) . 'mon_module/tpl';
$this->context->smarty->assign('tpl_path', $this->path_to_tpl_folder)
Then in your smarty template :
{include file=$tpl_path/my_file.tpl}
Compatible with Prestashop 1.4 and 1.5.

Is it possible to use include file as variable within include file

Is it possible to use an include file call as a variable within an include file call?
Below is an example of what I need:
{include file="data/data.inc.tpl" opts="{include file="data/dataset.inc.tpl"}"}
So the information from dataset.inc.tpl is used as a variable to display various options from data.inc.tpl
No, but you can capture the contents of the include in a variable:
{capture name=dataset}
{include file="data/dataset.inc.tpl"}
{/capture}
{include file="data/data.inc.tpl" opts=$smarty.capture.dataset}
or pass the file name to be included
{include file="data/data.inc.tpl" opts='data/dataset.inc.tpl'}
and then in data.inc.tpl...
{capture name=dataset}
{include $opts}
{/capture}

Smarty file exists syntax

Can you tell me what I am doing wrong? It is defaulting to my else statement even if a file does exist.
{assign var="wine" value="$smarty.const.DOC_ROOT/images/thumbs/$link.ID-300x225.png"}
{if file_exists($wine)}
File Exists!
{else}
File does not exist!
{/if}
Although you can't see the code, I do have backticks (backtick)$smarty.const.DOC_ROOT(backtick) and here (backtick)$link.ID(backtick)
When I use it like this it works but not in the example above:
<img src="{$smarty.const.DOC_ROOT}/images/thumbs/{$link.ID}-300x225.png" alt="" />
I replaced:
$smarty.const.DOC_ROOT
With the absolute path and it worked.
/home/user/public_html/etc...
Note:
$link.ID I put in backticks(``) otherwise it threw an error.

Resources