Get content from a block - bolt-cms

I´m currently building a website with Bolt as a CMS. But right now I´m struggling with getting the content out of a block. My contenttypes.yml:
blocks:
name: Blocks
singular_name: Block
fields:
title:
type: text
class: large
group: "Block"
slug:
type: slug
uses: [ title ]
text-one:
type: text
label: Tekst 1
group: content
text-two:
type: text
label: Tekst 2
group: content
text-three:
type: text
label: Tekst 3
group: content
text-four:
type: text
label: Tekst 4
group: content
text-five:
type: text
label: Tekst 5
group: content
text-six:
type: text
label: Tekst 6
group: content
My Twig code:
{% setcontent block_cta = "block/cta-nl" %}
Am I missing something?
Thanks in advance.

Hello your doing it a little bit wrong. if you want to get the value's out of an content type you should try this
{% setcontent name = "blocks" %}
you should call uppon the content type.
if you want to test what this gives back: {{ dump(test) }}
Hope this helps.

Related

Can you create template pages in Jekyll?

I have the following 2 pages:
---
<!-- pages/apple.md -->
title: Apple Nutrition Info
permalink: /info/apple
---
{% assign fruit = site.data.info.apple %}
Carbs: {{fruit.carbs}}
Sugar: {{fruit.sugar}}
![Apple](/assets/images/apple.png)
---
<!-- pages/orange.md -->
title: Orange Nutrition Info
permalink: /info/orange
---
{% assign fruit = site.data.info.orange %}
Carbs: {{fruit.carbs}}
Sugar: {{fruit.sugar}}
![Orange](assets/images/orange.png)
Since the pages' content are almost identical, is it possible to template the entire page itself, and somehow pass data like "apple", "orange", "banana" to the page?
I would love to do something like this:
---
<!-- pages/info.md -->
title: {{args.fruit | capitalize}} Nutrition Info
permalink: /info/{{args.fruit}}
---
{% assign fruit = site.data.info.{{args.fruit}} %}
Carbs: {{fruit.carbs}}
Sugar: {{fruit.sugar}}
![{{args.fruit | capitalize}}](assets/images/{{args.fruit}}.png)
Is this possible?
A bypass is to use collections instead of pages+data. (The doc on collections offers an example about authors with names and positions, similar to your fruits with carbs and sugar.)
_config.yml:
# …… (title, domain, plugins, etc.)
collections:
fruits:
output: true
permalink: /fruits/:name/
defaults:
- scope:
path: ""
type: fruits
values:
layout: fruit
(Permalinks pattern for collections can be different from pages, see Permalinks | Jekyll Doc if necessary.)
_layouts/fruit.md:
---
layout: default
---
- Carbs: {{ page.carbs }}
- Sugar: {{ page.sugar }}
![{{ page.name | capitalize }}](assets/images/{{page.name}}.png)
_fruits/apple.md:
---
name: apple
carbs: ○○
sugar: □□
---

How to access non current for-loop elements using the Liquid template system

I'm trying to access elements from the previous and next arrays. Is this even possible with liquid/Jekyll? I want to access the previous and next url of pages.
This is what I have done so far.
Thanks in advance.
To make sure that that liquid is working on my site I tested by outputting the current page url :
{{venue.url}}
//this line also works
{{page.url}}
and this is how I defied the array which takes the data from a yml file
{% assign page_venue = site.data.venues-array | where: "venueID", page.venue | first %}
This is part of the yml file:
venueID: Red-Radish
name: Red Radish
url: redradish
building: 65
neighborhood: University Union
venueID: Poly-Deli
name: Poly Deli
url: polydeli
building: 19
neighborhood: University Union
venueID: Myrons
name: Myron's
url: myrons
previous: MustangStation
building: 19
neighborhood: University Union
So I'm having trouble outputting something like this(only the current url works):
Current url: polydeli
Previous url: reddish
Next url: myrons
I've the tried the following, but none work:
<p>{{page.next.url}}</p>
<p>{{venue.next.url}}</p>
<p>{{paginate.next.url}}</p>
<p>{{paginator.next_page}}</p>
Updated:
First, you need to format the venues-array.yml file correctly, like so:
- venueID: Red-Radish
name: Red Radish
url: redradish
building: 65
neighborhood: University Union
- venueID: Poly-Deli
name: Poly Deli
url: polydeli
building: 19
neighborhood: University Union
- venueID: Myrons
name: Myron's
url: myrons
previous: MustangStation
building: 19
neighborhood: University Union
Then you can access the next and previous URLs like this:
{% for venue in site.data.venues-array %}
{% assign next = forloop.index0 | plus: 1 %}
{% assign previous = forloop.index0 | minus: 1 %}
<div>Name: {{ venue.name }}</div>
<div>Current URL: {{ venue.url }}</div>
<div>Previous url:{{ site.data.venues-array[previous].url }}</div>
<div>Next URL is:{{ site.data.venues-array[next].url }}</div>
<hr>
{% endfor %}
Which will out this:
Name: Red Radish
Current URL: redradish
Previous url:myrons
Next URL is:polydeli
Name: Poly Deli
Current URL: polydeli
Previous url:redradish
Next URL is:myrons
Name: Myron's
Current URL: myrons
Previous url:polydeli
Next URL is:

cant find the error in jekyll... "did not find expected key while parsing a block mapping"

I'm a relative newbee to jekyll and liquid. I had this running a while ago but messed it up somehow, without a backup. When finding something the error just shifts to somewhere else... Please take a look.
Here is my code:
---
title: Gallery
layout: gallery
heroimage: /img/hero-image-gallery.jpg
imgsize: small
masonry:
itemsize: 33.333%
categories:
- Objects
- People
- Places
images:
- title: one
thumb: img/gallery-image-one.jpg
big: img/gallery-image-one.jpg
categories:
- People
- Places
- title: two
thumb: img/gallery-image-two.jpg
big: img/gallery-image-two.jpg
categories:
- Objects
- Places
- title: three
thumb: img/gallery-image-three.jpg
big: img/gallery-image-three.jpg
categories:
- People
- title: four
thumb: img/gallery-image-four.jpg
big: img/gallery-image-four.jpg
categories:
- Objects
- Places
- title: five
thumb: img/gallery-image-five.jpg
big: img/gallery-image-five.jpg
categories:
- Objects
- title: eight
thumb: img/gallery-image-eight.jpg
big: img/gallery-image-eight.jpg
categories:
- Places
- title: seven
thumb: img/gallery-image-seven.jpg
big: img/gallery-image-seven.jpg
categories:
- Places
- title: six
thumb: img/gallery-image-six.jpg
big: img/gallery-image-six.jpg
categories:
- Objects
- People
- title: bla
thumb: img/gallery-image-six.jpg
big: img/gallery-image-six.jpg
categories:
- Objects
- People
---
<div class="portfolioFilter">
Alle
{% for cat in page.categories %}
{{cat}}
{% endfor %}
</div><br>
<div class="grid">
<div class="grid-sizer"></div>
{% for item in page.images %}
<div class="grid-item{% for cat in item.categories %} {{cat | slugify}}{% endfor %}">
<a class="example-image-link" href="{{item.big}}" data-lightbox="example-set" ><img src="{{item.thumb}}"/></a>
</div>
{% endfor %}
</div>
And here is the error I'm getting:
Error reading file /Users/maxborm/Desktop/lukawebsite/gallery.html: (<unknown>): did not find expected key while parsing a block mapping at line 2 column 1
Thanks in advance.
Indentation is very important in Liquid, and you have to make sure you have the right amount of spaces when declaring collections.
In your case, you have an extra space before - title: bla which is causing the error.
i.e. you have:
- title: bla
when you should have:
- title: bla

Sorted Map Iteration in Go Templates?

I'm building a website in Go, using the Hugo static site generator. What I'm trying to do is build a dynamic navigation bar for my web pages.
Here's what I'm doing:
In my config.yml file, I've defined a Map of links that I'd like to appear in my navbar -- here's what this file looks like:
baseurl: "https://www.rdegges.com/"
languageCode: "en-us"
title: "Randall Degges"
params:
navLinks: {"Twitter": "https://twitter.com/rdegges", "Facebook": "https://www.facebook.com/rdegges", "Google+": "https://plus.google.com/109157194342162880262", "Github": "https://github.com/rdegges"}
So, I've also got an index.html template in Hugo that contains a navbar which looks like this:
<nav>
<ul>
{{ range sort $title, $link := .Site.Params.navLinks }}
<li>{{ $title }}</li>
{{ end }}
</ul>
</nav>
This above code works correctly, with one exception: I'd like to order the results of my links instead of having them randomly ordered each time.
I know that Maps are not inherently structured in Go -- but is there a way to retain the original ordering of my navigation elements in some way?
Thanks for the help!
Go templates sort maps by key. If you want to force a specific order, then use a slice:
Here's the YAML:
baseurl: "https://www.rdegges.com/"
languageCode: "en-us"
title: "Randall Degges"
params:
navLinks:
- title: Twitter
url: https://twitter.com/rdegges
- title: Facebook
url: https://www.facebook.com/rdegges
... and the template:
<nav>
<ul>
{{ range $link := .Site.Params.navLinks }}
<li>{{ $link.title }}</li>
{{ end }}
</ul>
</nav>

How can I output raw unescaped html from this Rails route/helpers?

I am trying to use the following bit of code to generate a link on my page
%h2= link_to '{{ label }}', product_path('{{ id }}'.html_safe)
This is actually part of a larger HTML block which will serve as a javascript template, and I will later parse using Underscore.js to fill in the {{ id }} and {{ label }} placeholders. So I would like rails to output something to my HTML like
/products/{{ id }}
However, it keeps escaping the spaces and brackeets, and giving me
{{ label }}
So the url_helper is escaping my string, even though I don't want it to. How can I force it to not do this?
I've tried
%h2= link_to '{{ label }}', product_path('{{ id }}'.html_safe)
%h2= link_to '{{ label }}', product_path(raw '{{ id }}')
%h2= link_to '{{ label }}', raw(product_path('{{ id }}'))
and
%h2=raw( link_to '{{ label }}', product_path('{{ id }}'.html_safe))
But none of them work
EDIT:
Another way to play with this is from rails console,
include ActionController::UrlWriter
ruby-1.9.2-p0 :010 > product_path '{{ id }}'.html_safe
=> "/products/%7B%7B%20id%20%7D%7D"
Any help appreciated... thanks
Thanks
What about CGI::unescape(product_path('{{ id }}') ? (with the require 'cgi' that goes with it.)
I believe this is Ruby 1.9.2 only but it seems to be the version you're using.