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.
Related
I'm using Laravel 5 with Blade templates. My templates look like so:
drone.blade.php
#include('drone.gallery')
drone/gallery.php
{{ url('images-gallery/DSC_0072.JPG') }}
However, the url() function does not work inside my include file. If I copy the {{ url('images-gallery/DSC_0072.JPG') }} line into drone.blade.php it works as expected.
Why is the url() parameter not working inside include?
Thanks in advance.
I can see your filename is gallery.php.
Can you plaese change it to gallery.blade.php
I've been trying to make my own website for the past 3 days, and all was going fine working just with a HTML file, a CSS file, and a JavaScript file. Then yesterday I decided I'd try migrating what little I had of my site to a Jekyll-friendly structure so that I could have better management of my content. Here's what happened:
After following numerous tutorials and installing Ruby and the DevKit on my machine, I was finally able to get Jekyll to run locally. But I found that my index.html file in my root directory was not being inserted into my default.html template in the _layouts folder.
So Jekyll was building my site without using the default.html layout, it appeared, resulting in just the content in my index.html file being compiled into my final index.html file. My understanding was that instead of this, whatever was in the index.html file in the root directory would get inserted into a layout (specified in index.html's frontmatter), and the final index.html that Jekyll placed in the _site directory would be the amalgamation of index.html and default.html.
After long enough, I eventually tried renaming index.html in my root directory to index.md. Then, when I ran Jekyll again, the html code in index.md was inserted into the {{ content }} part in my layout default.html, which was what I had been wanting! Awesome, right? No. The problem then was that the frontmatter in index.md was actually SHOWING on my website:
Image of the frontmatter appearing on my local site
You can view all the complete code along with all my configuration details and directory structure here:
https://github.com/tygamvrelis/tylergamvrelis.github.io
So it seems then that SOMEHOW Jekyll is inserting the index.md content into the correct place in default.html, it's doing this without reading the frontmatter. In fact, I can delete the frontmatter in index.md entirely and my site looks perfectly fine, as long I leave at least 1 empty line at the start of my code. If I don't leave at least 1 empty line at the start of my code, then I see index.md on my website as raw HTML (tags and everything, no formatting).
I know this might not be sufficient information given the weirdness described, but I'd like to try understand what's going on and I appreciate any suggestions. If there's any other information you need from me to help solve this problem, please let me know.
Your index.md has BOM headers:
$ hd -n 3 index.md
00000000 ef bb bf |...|
00000003
As it is encoded with UTF-8, then the byte order mark follows the order: EF BB BF.
and Jekyll does not like them:
UTF-8 Character Encoding Warning
If you use UTF-8 encoding, make sure that no BOM header characters
exist in your files or very, very bad things will happen to Jekyll.
So you need to remove them and Jekyll will be happy again:
$ tail -c +4 index.md > UTF8.nobom
$ mv UTF8.nobom index.md
Or look how to remove them with awk or sed
I am building my blog using Jekyll, and originally planned to only use Jekyll for the homepage. Because of this, I had created other non-changing html pages in their respective directories, and they work just fine. However, I've recently been thinking about making a separate page to list all posts I've made thus far, and would thus need to reference the "main" site's posts.
My project's structure looks like the following:
_includes/
footer.html
header.html
sidebar.html
_layouts/
default.html
posts.html
_posts/
...
_site/
...
about/
index.html
archive/
index.html
css/
style.css
resume/
index.html
_config.yml
index.html
I would like to list all posts I've made in the archive/index.html page. I attempted this by doing the following:
...
<h2>The Archive.</h2>
{% for post in site.posts %}
<h4>{{ post.title }}</h4>
<p><small>{{ post.date | date: "%B %e, %Y" }}</small></p>
{% endfor %}
...
However, that archive/index.html page only renders the above as text.
I have also tried creating an entirely new Jekyll directory structure inside the archive directory, but this doesn't seem to work either.
How can I make it so that the archive/index.html page recognizes the for loop for listing all my site's posts?
I've forked your repo and this archive/index.html works well :
---
layout: default
---
<h2>The Archive.</h2>
{% for post in site.posts %}
<h4>{{ post.title }}</h4>
<p><small>{{ post.date | date: "%B %e, %Y" }}</small></p>
{% endfor %}
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
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.