Using a Jekyll for loop in a different directory - ruby

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 %}

Related

Loop over CSV rows in jekyll

I'm encountering some issues with loading data from a csv file with jekyll.
I've made some custom collections using the following _config.yml seup:
collections_dir: collections
collections:
people:
output: true
publications:
output: true
Now I this is what my structure looks like (just showing the relevant parts):
.
├── collections
│   ├── _people
│   │   ├── x.md
│   │   ├── y.md
│   └── _publications
│       └── data.csv
├── index.html
└── _config.yml
When I try to loop over my collections using this link as a guide it doesn't seem to work
# except from my index.html file
{% for row in site.publications.data %}
<p>name: {{row.name}}</p>
{% endfor %}
I think you are after a data file, rather than a collection here. The main differences are:
Data files can have each item as entries in a single file, or separate files in a subfolder of _data
Collections have each item as a separate file only
Data entries do not output a page per entry
Collections can output a page per entry
Here's how you would change this to data:
Move collections/publications/data.csv to _data/publications.csv
Remove the publications entry from collections in _config.yml
Change your loop to the following:
{% for row in site.data.publications %}
<p>name: {{ row.name }}</p>
{% endfor %}
If you want to use a data file and output a page per entry, a popular plugin to do so is https://github.com/avillafiorita/jekyll-datapage_gen
Alternatively, you could split the CSV into separate Markdown files and use a collection to avoid adding a plugin.

Wrire script in Laravel

I want to write <scrip></script> for API address form but I don't know where to write .
I created file a script.php in resources/views/script.php then I call
<script src= "{{ asset('resources/views/script.php') }}" >in app.blade.php but didn't work
Change your script.php name to script.blade.php then you can import it using #include('script');
Change resources/views/script.php to resources/views/script.blade.php
Then you can use the blade template engine :
#include('script');

url() parameter not working in Blade template include

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

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.

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

Resources