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

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}

Related

Jekyll - Include file to point to its own md file

If I include a file like so:
{% include_relative _layouts/tile.html %}
within my index.html file, how can I get tile.html to use the front matter of tile.md rather than index.md?
It should be better to have the title in the config or a data file.
But in this case, if you want to access the frontmatter of any post/page you can do it by specifying the path where it is located as:
{%assign title_post = site.posts | where:"path","_posts/title.md" |first%}
{{title_post.title}}
Or if it is a page (as it seems to be) use site.pages instead of site.posts.

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

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 !

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.

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