Hugo markdown metadata - yaml

I want to show metadata from the markdown file on the webpage so I'm trying to access it using the variable names (e.g. {{ .Author}} ).
This works fine with the .Title and .Content variables, but does not work with the others! It seems like I'm missing an important detail on how to use these. With the .Author variable the output on the page is { map[]}.
Thanks in advance
Markdown file:
---
title: ABC
author: "Foo Bar"
position: Manager
---
The actual content ...
Webpage:
{{ range where .Data.Pages "Type" "type"}}
<section>
<div>
<div>
{{ .Title }}<br>
{{ .Content }}
</div>
<div>
{{ .Author }}<br>
{{ .Position }}
</div>
</div>
</section>
{{ end }}

Turns out you need to access the non-standard parameters via the .Params variable.
See https://gohugo.io/variables/page/ for the relevant information.
{{ range where .Data.Pages "Type" "type"}}
<section>
<div>
<div>
{{ .Title }}<br>
{{ .Content }}
</div>
<div>
{{ .Params.author }}<br>
{{ .Params.position }}
</div>
</div>
</section>
{{ end }}

If you are building a menu, it seems .Params.author fails. So this should work:
Let’s say you have in your .md file the metadata:
author: Bob Dole
menu: "guest"
Your menu can access the author if you use {{ with .Page }} and {{ .Params.author }}
{{ range .Site.Menus.guest }}
<div>
{{ with .Page }}
{{ .Name }} - {{ .Params.author}}
{{ end }}
</div>
{{ end }}

Related

how to access properties from Laravel collections within foreach

I have a Laravel collection with relations returned to a view and I need to access it's properties;
controller
$project = Project::with('pulls.builds')->where('id',$id)->get();
view
#foreach ($project as $project->pulls)
{{ $project->pulls }}
#endforeach
output
{"id":2,"created_at":null,"updated_at":null,"name":"Project Name","pulls":[{"id":2,"created_at":null,"updated_at":null,"branch":".fixes","project_id":2,"builds":[{"id":3,"created_at":null,"updated_at":null,"description":"43662-4768-456","pull_id":2}]},{"id":3,"created_at":null,"updated_at":null,"branch":".test","project_id":2,"builds":[{"id":4,"created_at":null,"updated_at":null,"description":"build 1","pull_id":3}]}]}
I have all the data that I want, now I need to make it look like this when viewed by the user:
Project Name
.fixes
43662-4768-456
.test
build 1
$projects = Project::with('pulls.builds')->where('id',$id)->get();
Given the structure of the json, to echo out every property you'd need to do something like this
#foreach($projects as $project)
{{ $project->id }}
{{ $project->created_at }}
{{ $project->updated_at }}
{{ $project->name }}
#foreach($project->pulls as $pull)
{{ $pull->id }}
{{ $pull->created_at }}
{{ $pull->updated_at }}
{{ $pull->branch }}
{{ $pull->project_id }}
#foreach($pull->builds as $build)
{{ $build->id }}
{{ $build->created_at }}
{{ $build->updated_at }}
{{ $build->description }}
{{ $build->pull_id }}
#endforeach
#endforeach
#endforeach
So taking only what you need, and adding some html, it could end up looking like this:
<p>Projects:</p>
#foreach($projects as $project)
<p>Project Name: <span>{{ $project->name }}</span></p>
<p>Pulls:</p>
#foreach($project->pulls as $pull)
<p>Branch: <span>{{ $pull->branch }}</span></p>
<p>Builds:</p>
#foreach($pull->builds as $build)
<p>Description: <span>{{ $build->description }}</span></p>
#endforeach
#endforeach
#endforeach
If you only want a single project, instead of using ->where('id', $id)->get(), use ->find($id) and you can remove the first #foreach.

unexpected "=" in operand

I am getting this error in a Hugo theme and have modified the code to use a simple example from the Hugo documentation and still get an error.
unexpected "=" in operand
Hugo Version
Hugo Static Site Generator v0.40.1 linux/amd64 BuildDate: 2018-04-25T17:16:11Z
Go Version
go version go1.12 linux/amd64
I have copied this code directly from the GoHugo - Append example.
Error
ERROR 2019/03/11 09:24:53 theme/partials/work.html : template: theme/partials/work.html:3: unexpected "=" in operand
Simplified Template
{{ partial "global-header.html" . }}
{{ $s := slice "a" "b" "c" }}
{{ $s = $s | append "d" "e" }}
<h1>David</h1>
I originally got the error in the Hugo AirSpace template at line 13 of the work.html partial.
Sample Line
{{ $categories = $categories | append .category }}
Full Template
{{ partial "global-header.html" . }}
<!-- Portfolio Start -->
<section id="portfolio-work">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="block">
<div class="portfolio-menu">
<ul>
{{ $categories := slice }}
{{ range .Site.Data.work.portfolio }}
{{ $categories = $categories | append .category }}
{{ end }}
<li class="filter" data-filter="all">Everything</li>
{{ range ( $categories | uniq ) }}
<li class="filter" data-filter=".{{ . }}">{{ . }}</li>
{{ end }}
</ul>
</div>
<div class="portfolio-contant">
<ul id="portfolio-contant-active">
{{ range .Site.Data.work.portfolio }}
<li class="mix {{ .category }}">
<a class="venobox" href="{{ $.Site.BaseURL }}{{ .image }}">
<img class="img-responsive" src="{{ $.Site.BaseURL }}{{ .image }}" />
<div class="overly">
<div class="position-center">
<i class="fa fa-search fz-20"></i>
<h2>{{ .name }}</h2>
<p>{{ .description }}</p>
</div>
</a>
</li>
{{ end }}
</ul>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Clients Logo Section Start -->
<section id="clients-logo-section">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="block">
<div id="clients-logo" class="owl-carousel">
{{ range .Site.Data.work.clients }}
<div class="clients-logo-img">
<img src="{{ $.Site.BaseURL }}{{ .image }}" alt="Features">
</div>
{{ end }}
</div>
</div>
</div>
</div>
</div>
</section>
I found that my version of go was old and it needed updating to 1.11
I followed the instructions found here
install-go-1-11-on-ubuntu
I had one slight variation, I used Go1.12 instead of 1.11
# From the docs
sudo tar -xvf go1.11.linux-amd64.tar.gz
# This is the latest version when I updated
sudo tar -xvf go1.12.linux-amd64.tar.gz
I also had to update my version of hugo.
Any time I did the following
sudo apt-get install hugo
I ended up with version 40
I followed the instructions here to go to version 53 of GO

use nested foreach for showing posts and comments in laravel

how can i use nested foreach for showing posts and comments in laravel ?
this is my Route :
Route::get('/showpost', function () {
$showpost = Posts::all();
$comment = Comment::all();
return view('showpost', compact('showpost', 'comment'));
});
and here it's my view :
<h1>Posts :</h1>
#foreach($showpost as $showpost)
<h1>{{ $showpost->Title }}</h1>
<h5>{{ $showpost->Content }}</h5>
{{ Form::open(array('url'=>'showpost','method'=>'post')) }}
<h5>{{ Form::label('Comment : ') }} {{ Form::text('Comment') }}</h5>
{{ Form::hidden('invisible', $showpost->ID) }}
{{ Form::submit('Send Comment') }}
{{ Form::close() }}
<hr style='margin-top: 10%'>
#endforeach
<hr>
<h1>Comments :</h1>
#foreach($comment as $comment)
{{ $comment->Comment }} -> {{ $comment->PostID }} <br>
#endforeach
Posts show here and a textbox under it show too and we can add comment
i want to show comments about the posts under each posts
now i can't use nested foreach!!!
You should use eloquent relationship(). In your post model-
public function comments()
{
return $this->hasMany('App\Comment');
}
And then in your controller -
$showposts = Posts::with('comments')->get();
return view('showpost')->with('showposts', $showposts);
And in your view-
<h1>Posts :</h1>
#foreach($showposts as $showpost)
<h1>{{ $showpost->Title }}</h1>
<h5>{{ $showpost->Content }}</h5>
{{ Form::open(array('url'=>'showpost','method'=>'post')) }}
<h5>{{ Form::label('Comment : ') }} {{ Form::text('Comment') }}</h5>
{{ Form::hidden('invisible', $showpost->ID) }}
{{ Form::submit('Send Comment') }}
{{ Form::close() }}
<hr style='margin-top: 10%'>
<hr>
<h1>Comments :</h1>
#foreach($showpost->comments as $comment)
{{ $comment->Comment }} -> {{ $comment->PostID }} <br>
#endforeach
#endforeach
This way you will get comments associate with your posts.

Why do i have a form url point at thesame location but not at a specific file that will insert my data into database

My LoginUser.blade.php
<h1>Login</h1>
{{-- Form start comment --}}
{{ Form::open(array('url' => 'user/loginUser')) }}
<p>
{{ Form::label('email', 'E-Mail Address') }}
{{ Form::email('email', null, array("placeholder" => "Enter your email")) }}
</p>
<p>
{{ Form::label('password', 'Password') }}
{{ Form::password('password', array("placeholder"=>"Enter your password")) }}
</p>
<p>
{{ Form::submit('Sign In') }}
</p>
{{ Form::close() }}
{{-- Form end comment --}}
So my Question is why should my URL points to my current LoginUser.blade.php which contains the HTML forms?? Please am new to laravel am using laravel 5.2

Liquid nesting For-Loop Syntax issue in Jekyll

First time posting, so thanks in advance for your time c:
I'm using Jekyll to serve a portfolio. I'm using a portfolio plugin as well as a JS library called Lightbox. I have the portfolio plugin working. The ideal action is that every time the user clicks a portfolio item, it executes the lightbox (that's working). In order to for more images to be stored in the lightbox, I must give them the same data-title name.
My understanding is that I need to nest a for-loop within my current loop, to check for all items within the array to return any additional lightbox items.
My .yml file reads like so:
title: Portfolio Title
description: A crazy portfolio item
bg-image: Test-01.png
lb-images:
- Test-01.png
- Test-02.png
- Test-03.png`
My .md file reads like so:
<div class="flex-container">
<!-- portfolio-item -->
{% assign projects = site.data.projects | get_projects_from_files | sort:'date' %}
{% for project in projects reversed %}
<div class="flex-item" style="background-image: url(/img/projects/{{ project.bg-image }}); background-repeat: no-repeat">
<a href="../images/projects/{{ project.lb-images[0] }}" data-lightbox="{{ project.title }}" data-title="{{ project.bg-image }}">
<div id="overlay">
<span id="reveal-text">
<h3>{{ project.title }}</h3>
<p>{{ project.description }}</p>
<p>{{ project.category }}</p>
</span>
</div>
</a>
</div>
{% for project in projects %}
{% endfor %}
{% endfor %}
</div>
I assumed that the forloop.index would begin at [1] and then continue through that array until there are no more lb-images. But something's up. My guess is syntax or how I'm calling the data from the .yml file, or both.
Again thanks for your time.
Daniel
(edit: took out space in nested endfor loop, runs now but returns: href="../images/projects/] }}" and data-title and data-lightbox returns are for each data.project file instead of for each item in data.project.lb-images)
Correct loop to expose images for a project is:
{% assign projects = site.data.projects | get_projects_from_files | sort:'date' %}
<div class="flex-container">
{% for project in projects reversed %}
<!-- portfolio-item -->
<div class="flex-item" style="background-image: url(/img/projects/{{ project.bg-image }}); background-repeat: no-repeat">
<a href="../images/projects/{{ project.lb-images[0] }}" data-lightbox="{{ project.title }}" data-title="{{ project.bg-image }}">
<div id="overlay">
<span id="reveal-text">
<h3>{{ project.title }}</h3>
<p>{{ project.description }}</p>
<p>{{ project.category }}</p>
</span>
</div>
</a>
</div>
{% for img in project.lb-images %}
{% if forloop.first != true %}
{% endif %}
{% endfor %}
{% endfor %}
</div>
Liquid forloop documentation

Resources