I'm trying to display up to three related articles at the bottom of a blog post using Hugo.
I have some test code where I get data for front matter fields like Title and Summary, but I can't access Image.
Not sure what I am doing wrong
{{ $related := .Site.RegularPages.Related . | first 3 }}
{{ with $related }}
<div class="related-content">
<h2>Related content</h2>
<ul class="article-gallery">
{{ range . }}
<li>
<div class="card">
<a class="button" href="{{ .RelPermalink }}">
<img src="" alt ="">
</a>
<div>
<h3>{{ .Title }}</h3>
</div>
<pre>
{{.RelPermalink}}
{{.Title}}
{{.Summary}}
{{.}}
{{.ReadingTime}}
</pre>
<!-- Cannot Access Image -->
<pre>
{{.Image}}
</pre>
</div>
</li>
{{ end }}
</ul>
</div>
{{ end }}
Custom, user-defined data elements in a page's front matter needs to be accessed through .Params:
{{ .Params.Image }}
See The Hugo Docs
Note: there is a predfined "images" (with an 's') that can be accessed directly. Did you mean to use that instead?
Related
I have a data JSON file locally where I can get the data into a component and print the object value depending on the object array number starting from 0 and on ... how can I print it using the object's id value?
in resolution as an example id=321 I want to print that object.
here is my current working code printing by object array value:
<template>
<div class="exespotbody">
<center><h2> Stories Spotlight </h2></center><br>
<div class="Fgrid">
<!-- single news Block for data-->
<a
v-bind:key="dataList[0].id"
:href="`posts/${dataList[0].id}`"
class="Gmodule"
style="display:flex;text-decoration:none;color:#14a0fd;"
>
<div>
<!-- <img src="https://fintechapp.s3.us-east-2.amazonaws.com/y2qYjf8e2hp8z5yrgyfxF2NN?response-content-disposition=inline%3B%20filename%3D%22BoxLogo.png%22%3B%20filename%2A%3DUTF-8%27%27BoxLogo.png&response-content-type=image%2Fpng&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJG6DG75G7BXQ3XUA%2F20210115%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20210115T192217Z&X-Amz-Expires=518400&X-Amz-SignedHeaders=host&X-Amz-Signature=26b742c676a7fc0854c1efa0c81bf60e9239bc5068606262b3b1eab0f7a21245">
-->
<img :src="`{{ dataList[0].logo_url}}`"> </img>
<h6> {{ dataList[0].title }} </h6>
<!-- <p v-html="dataList[0].blog_entry"> </p> -->
<hr>
<p> {{ dataList[0].author.name }} </p>
<p> {{ dataList[0].author.title}} </p>
</div>
</a>
<!-- single news Block for data END-->
</div>
</div>
</template>
<script>
import dataData from "#/data/data.json";
export default {
name: 'StoriesSpotlight',
data() {
return {
dataList: dataData,
}
}
}
</script>
the result on screen :
Here is a is Vue tools pic for data:
what I want to do is print the data of the object bind by the id of the object for example id=321 that would be my next step...
So you want to find an object by its id from an array, then you can use find() on dataList
dataList.find(item => item.id === 321).title
dataList.find(item => item.id === 321).author.name
dataList.find(item => item.id === 321).author.title
I might be misreading this question, but I think you're talking about using object properties?
If so, just copy the lines used for displaying the other object properties
<img :src="`{{ dataList[0].logo_url}}`"> </img>
<h6> {{ dataList[0].title }} </h6>
<h6> ID: {{ dataList[0].id }} </h6>
<!-- <p v-html="dataList[0].blog_entry"> </p> -->
<hr>
<p> {{ dataList[0].author.name }} </p>
<p> {{ dataList[0].author.title}} </p>
For iterating across the full dataList Use v-for
<div v-for="entry in dataList" key="entry.id" class="Fgrid">
<!-- single news Block for data-->
<a
v-bind:key="entry.id"
:href="`posts/${entry.id}`"
class="Gmodule"
style="display:flex;text-decoration:none;color:#14a0fd;"
>
<div>
<!-- <img src="https://fintechapp.s3.us-east-2.amazonaws.com/y2qYjf8e2hp8z5yrgyfxF2NN?response-content-disposition=inline%3B%20filename%3D%22BoxLogo.png%22%3B%20filename%2A%3DUTF-8%27%27BoxLogo.png&response-content-type=image%2Fpng&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJG6DG75G7BXQ3XUA%2F20210115%2Fus-east-2%2Fs3%2Faws4_request&X-Amz-Date=20210115T192217Z&X-Amz-Expires=518400&X-Amz-SignedHeaders=host&X-Amz-Signature=26b742c676a7fc0854c1efa0c81bf60e9239bc5068606262b3b1eab0f7a21245">
-->
<img :src="`{{ entry.logo_url}}`"> </img>
<h6> {{ entry.title }} </h6>
<!-- <p v-html="entry.blog_entry"> </p> -->
<hr>
<p> {{ entry.author.name }} </p>
<p> {{ entry.author.title}} </p>
</div>
</a>
<!-- single news Block for data END-->
</div>
I have a nav.html partial with this in it:
<div class="dropdown-menu dropdown-primary" aria-labelledby="navbarDropdownMenuLink">
{{ range $.Data.Pages }}
{{ if ( not ( .IsPage) )}}
<a class="dropdown-item" href={{ .Permalink }}>{{ .Name }}</a>
{{ end }}
{{ end }}
</div>
It works on the root of my site, but does not work when rendering a page or list "inside" the site.
How do I access the "root" context .Data.Pages no matter where I am in the site so my nav partial works all the time?
I found it, .Data.Pages is for the current node, I wanted this:
{{ range $.Site.Pages }}
{{ if ( eq .Kind "section" )}}
<a class="dropdown-item" href={{ .Permalink }}>{{ .Name }}</a>
{{ end }}
{{ end }}
https://gohugo.io/variables/page/
I have this code:
<main class="gallery">
<nav class="gallery-list-thumbs">
<ul>
<li ng-click="showLarge($event); modalShow()" ng-repeat="photo in photos | filter:{'section': section }">
<img data-ref="ref-{{ photo.id }}" data-orientation="{{ photo.orientation }}" class="photo-small" ng-src="photos/{{ photo.section }}/th/{{ photo.src }}">
</li>
</ul>
</nav>
<section class="gallery-item" ng-hide="modalHidden">
<h1 ng-model="section">{{ section }}</h1>
<div class="photo-container">
<div class="modal-close" ng-click="modalShow()"></div>
<div class="modal-prev"></div>
<div class="modal-next"></div>
<img data-photoref="ref-{{ photo.id }}" ng-repeat="photo in photos | filter:{'section': section }" class="photo-large below orientation-{{ photo.orientation }}" ng-class="{'above':$first}" ng-src="photos/{{ section }}/{{ photo.src }}">
</div>
</section>
</main>
What I hope to achieve, is to hide the modal-prev when the user click on the first li in gallery-list-thumbs and the same thing with modal-next on the last li.
So far, using $index, it's fairly easy since I can target it by a scope change, but how do I get the last element when there's a different amount of images per galleries? It would be easier if the next and prev arrows were inside the ng-repeat since I could use $first and $last, but I don't want to have to include them in.
OK, I was able to find it by myself.
The solution was to change a scope on $first and last and then add a ng-show and ng-hide depending on the scope value.
Here's the code if anyone has this kind of issue:
<main class="gallery">
<nav class="gallery-list-thumbs">
<ul>
<li ng-click="showLarge($event); modalShow();setPosition('inbetween'); $first && setPosition('first') ; $last && setPosition('last')" ng-repeat="photo in photos | filter:{'section': section }">
<img data-ref="ref-{{ photo.id }}" data-orientation="{{ photo.orientation }}" class="photo-small" ng-src="photos/{{ photo.section }}/th/{{ photo.src }}">
</li>
</ul>
</nav>
<section class="gallery-item" ng-hide="modalHidden">
<h1 ng-model="section">{{ section }}</h1>
<div class="photo-container">
<div class="modal-close" ng-click="modalShow()"></div>
<div class="modal-prev" ng-hide="currentOrder == 'first';">{{ currentOrder }}</div>
<div class="modal-next" ng-hide="currentOrder == 'last';">{{ currentOrder }}</div>
<img data-photoref="ref-{{ photo.id }}" ng-repeat="photo in photos | filter:{'section': section }" class="photo-large below orientation-{{ photo.orientation }}" ng-class="{'above':$first}" ng-src="photos/{{ section }}/{{ photo.src }}">
</div>
</section>
</main>
In my application there is a carousel with images that I get from my service. Under the carousel there are 3 buttons that give more information about the image.
These information buttons should replace the bullet indicators for a standard carousel. The buttons get an active class when the corresponding image is displayed so it stands out from the other 2.
Below is my code, I'm using this carousel
<ul rn-carousel>
<li ng-repeat="promo in promos">
<img ng-src="{{ promo.slider[0].slide }}" alt="{{ promo.name }}">
</li>
</ul>
<div ng-repeat="promo in promos">
<button>
<h2>{{ promo.name }}</h2>
<p>- {{ promo.descr }} <span>{{ promo.disc }}</span></p>
</button>
</div>
I have no problems getting the info out of my service, it's just the linking part that is giving me problems.
I found the solution after searching through the issues page of the carousel I'm using.
<ul rn-carousel rn-carousel-index="currentSlide">
<li ng-repeat="promo in promos">
<img ng-src="{{ promo.slider[0].slide }}" alt="{{ promo.name }}">
</li>
</ul>
<div ng-repeat="promo in promos">
<button ng-class="{activeBtn: $index==$parent.currentSlide}" ng-click="$parent.currentSlide = $index">
<h2>{{ promo.name }}</h2>
<p>- {{ promo.descr }} <span>{{ promo.disc }}</span></p>
</button>
</div>
I had to name my carousel-index and for my indicators I had to refer to the parent element for the binding to work.
Thanks to Capricorn for leading the way.
I'm in the middle of learning Angular, and I am attempting to show or hide contents in a content div depending on side menu items being clicked.
<div id="side-menu">
<h3>Side Menu</h3>
<div ng-repeat="item in example">
<p ng-click="collapsed=!collapsed">
API Name: {{ item.name }}
</p>
</div>
</div>
<div id="content">
<h3>Content</h3>
<!-- What do I have to add here to "connect" to "item in example"? -->
<div ng-show="collapsed">
<p>Debug: {{ item.debug }}</p>
<p>Window: {{ item.window }}</p>
</div>
</div>
What do I have to add to controller ng-show from the other div?
Use $parent:
ng-click="$parent.collapsed=!$parent.collapsed"
Example: http://jsfiddle.net/cherniv/6vhH3/
Read this to understand the most important basics of Angular' scopes.