Creating nesting menus on Hugo theme? - web

I am trying to build a website with Hugo. I am having some trouble getting nested menus set up.
I am using the Tokiwa theme for this project.
here is a link to my repo.
On the main page of the site I am trying to create menus that slide down to show subfolders, here is an example from the imperial-library site to show what I mean. You can click on “game books” and then a list opens up that shows all of the available topics for that option. Ex (All, Arena, …) If you click on one of the topics it takes you to a page with a list of all of the entries and a short description of each one. You can then click on the entry to view that post.
In my project my directory is structured
content -> writing (Writing has subfolders poem and stories)
So on the home page I would like for someone to be able to click on “writing” then it would slide down to reveal “poems” and “stories”. You could then click on either one of those to view a list page formatted like
description of poem 1 - link to poem 1
description of poem 2 - link to poem 2
description of poem 3 - link to poem 3
I would also like to add this feature to other topics than only writing.
My config.toml file has the following
sectionPagesMenu = "main"
[menu]
[[menu.main]]
identifier = "writing"
name = "writing"
url = "/writing"
weight = 1
[[menu.main]]
identifier = "post"
name = "post"
url = "/post"
weight = 2
[[menu.main]]
identifier = "poems"
name = "poems"
url = "/category/poems"
parent = "writing"
weight = 1
[[menu.main]]
identifier = "stories"
name = "stories"
url = "/category/stories"
parent = "writing"
weight = 2
in my layouts/index.html
{{ define "menu-item" }}
{{ $page := .page }}
{{ with .entry }}
{{ if .HasChildren }}
<li class="{{ if $page.HasMenuCurrent "main" . }}active{{ end }}">
{{ .Name }}
<ul class="sub-menu">
{{ range .Children }}
{{ template "menu-item" (dict "entry" . "page" $page) }}
{{ end }}
</ul>
</li>
{{ else }}
<li class="{{ if $page.IsMenuCurrent "main" . }}active{{ end }}">
{{ .Name }}
</li>
{{ end }}
{{ end }}
{{ end }}
<ul>
{{ $page := . }}
{{ range .Site.Menus.main }}
{{ template "menu-item" (dict "entry" . "page" $page) }}
{{ end }}
</ul>
I also tried following this example from the hugo docs
Currently my site displays with the theme and when I click on a link the url seems correct ex writing/poems/poem1.
However, the folders are not displaying correctly.
I have posted this as well on the hugo forums and was unable to quite get my question answered. I browsed through many of the topics on "nesting menus" on the hugo forums and was still unable to exactly figure this out.
Thank you

I asked about this on the Tokiwa github.
The solution was to
Put custom.css and custom.js into static/lib/ folder, and add two lines in baseof.html:
<link rel="stylesheet" href='{{"lib/custom.css"|absURL}}' crossorigin="anonymous">
<script src='{{"lib/custom.js"|absURL}}' crossorigin="anonymous"></script>
Before </head> tag.

Related

How to paginate my jekyll site using Jekyll-Paginate-v2

Here is the source code of the website with its index.md and config.yml.
The problem
The number of tools (.md files) in _wadcoms directory keeps increasing over time, so I want the main page to be paginated in order to better navigate among plenty of them.
I tried several blogs and followed them all step by step individually, but unfortunately, I couldn't document each one of them here, still, my Jekyll site won't render that pagination.
Just now I found out that Pagination only works within HTML files, despite the solutions and workarounds suggested in that thread, I am unable to follow it up with my website. It renders the main page from the index.md file, I am not able to convert it to index.html which would help my site paginate.
What I wanted
I wanted to have ellipses to paginated the site using Jekyll-Paginate-v2, just like in the answer thread. I am absolutely out of ideas and I have no clue how to proceed with rendering a successful pagination in this case.
NOTE: Those files under _wadcoms are individual webpages, they increase in number over time, that's why I needed pagination on the main site. Imagine 200 of these tools/commands, that would be very difficult to navigate.
Thanks for your help.
Following my comment above, I have tested the plugin.
The result is not a numbered pagination yet but this should be also possible. Note that I converted the paragraphs, logo, and links in the index to HTML tags (p, img and a) but this worked OK:
I have not tested the search ... I hope that this is a trace and helps a bit. You can find my complete test code I comment below in a branch/PR in your repo: https://github.com/WADComs/WADComs.github.io/pull/21
I have replaced the current code in bin_table.html with
<!-- not sure about the reverse, the plugin offers this option, too! -->
{% assign sites = paginator.wadcoms | reverse %}
{% for file in sites %}
<tr>
<td>
<div class="bin-name">
<div style="flex: 0 0 97%"><a href="{{ file.url }}" id="{{ file.url }}"
style="text-decoration: none; color: DarkGreen;">{{ file.command | escape }}</a></div>
<div style="flex: 1;"><a href="javascript:void(0)" onClick="copyFunction('{{ file.url }}')"><img
src="/assets/copy-button.svg" alt="Copy" title="Copy" id="{{ file.url }}_img" /></a>
</div>
</div>
<p style="margin-top: -12px;">{% include filter_list.html bin=file %}</p>
</td>
</tr>
{% endfor %}
Previous page | Next page
{{ paginator.page }}
{{ paginator.total_pages | inspect }}
{% for page in paginator.total_pages %}
{{ page }}
{% endfor %}
I have added these lines to the _config.yml file (as an example config):
paginate:
collection: wadcoms
per_page: 10 # maximum number of items per page
limit: false # Maximum number of pages to paginate (false for unlimited)
permalink: /page:num/ # pagination path (relative to template page)
title_suffix: " - page :num" # Append to template's page title
category: '' # Paginate items in this category
categories: [] # Paginate items in any of these categories
tag: '' # Paginate items tagged with this tag
tags: [] # Paginate items tagged with any of these tags
reversed: true # Reverse the order of the documents

Hugo's Paginate isn't using my custom filter

I'm using Paginate to make a list of my projects on my homepage (index.html). I'm trying to show only pages with the type "code", but it doesn't work - it shows all kinds of pages (see here - note "Calendar" and "About" shouldn't be in this list).
{{ $paginator := .Paginate (where .Site.Pages "Type" "code") }}
{{ range $paginator.Pages }}
{{ partial "list.html" . }}
{{ end }}
{{ partial "paginator.html" . }}
The idea of this code is that I create an array of pages of the type "code", and put them into Hugo's Paginate. I then range through the contents of Paginate in the {{ range }} block.
This is sort of happening, but the filter isn't working at all - it's displaying content outside of the /code/ folder.
Repo here.
I've tried this in many different ways. Applying the filter to the {{ range $paginator.Pages }} sort of works, but also breaks Paginate a bit, since Paginate has a different number of posts than the range it's displaying. I've tried different variations to filter Paginate too, such as (where Site.RegularPages "Type" "code"). Nothing has worked!
I've seen posts on StackOverflow (which I can no longer find) saying that this issue is caused by using Paginate more than once on the page, but I've checked through all my files and the theme files, and I can't find it being used anywhere apart from the one instance I'm trying to get to work.
Edit: I've just changed my code from "Type" to "Section", like this:
{{ $paginator := .Paginate (where .Site.Pages "Section" "code") }}
{{ range $paginator.Pages }}
{{ partial "list.html" . }}
{{ end }}
{{ partial "paginator.html" . }}
Still doesn't work.

Craft CMS access image from a different entry using ID

Hi how do I access an image from a different entry / page /url? I'm building in Craft CMS.
I'm creating a nav that will be used across the site. It works fine and I can pull the title and page url ok. I want to use a picture from that page as a thumbnail for the link but it doesn't work.
On my page I have 4 or 5 featured images but I just want to access the first one. What ever I try doesn't work
{% set image = craft.entries.id(50 ####this is the page ID that the image is attached to).featuredImages %} - doesn't work.
Basically how do I access an image when all I have is the id number of the page it is attached on?
Any help would be much apreciated,
Thanks.
Phew, found it. Perhaps there's a cleaner way but:
{% set pageData = entry.id(50) %} ## or in my case swap 50 with node.entryId as I'm using Navee plugin to build my nav.
{% set x = 1 %}
{% for image in pageData.featuredImages %}
{% if x == 1 %}
<img class="navImage" src="{{ image.getUrl('siteThumb') }}" alt="{{ page.title }}">
{% set x = 2 %}
{% endif %}
{% endfor %}

If statement in Twig (for Particle in Joomla)

Trying to edit a particle in Joomla -- I'm fairly new to twig and I'm trying to list information based on a selection in vertical tabs. I have an on-click refresh for my li edit that makes a tab "selected" and creates my internal url:
{% for item in particle.items %}
<li>
<a href="/Joomla/about-the-library/locations#{{ loop.index }}">{{ item.title|e }}
<img src="{{ url(item.image)|e }}" alt="{{ item.title|e }}">
<div class="g-flexslider-carousel-item-image-preview-icon"></div>
</a>
</li>
{% endfor %}
This is all well and good, but I ran into an issue when trying to display the data associated with the selected item. I tried to create a variable to check my items against, but the variable doesn't seem to be coming back as an integer, and I've tried a few things:
{% set branch = app.request.pathinfo|trim('/Joomla/about-the-library/locations#') %}
{% if loop.index == branch %}
<div class="g-flexslider-showcase-item-content-container">
<div class="g-flexslider-showcase-item-image">
<img src="{{ url(item.image)|e }}" alt="{{ item.title|e }}">
</div>
Can anyone tell me what I'm doing incorrectly?
(I found that get current url in twig template? helped, but I'm not sure I'm using the answers provided correctly. I've also sifted through the Twig Documentation for a couple hours to no avail.)
[Nov 2016] - This is still what "my" code looks like for this section. It seems to just be a problem with this if statement, as the "else" statement (which I'm using for debugging purposes) keeps coming through.
{% for item in particle.items %}
{% if app.request.get('name') == item.URLname|e %}
<p>You have branched {{ item.title|e }} correctly. </p>

Retrieve a value inside a field using a custom twig / Select a column by it's block name / Sonata

I'll try to be clear as possible, as my question may not be simple.
I have a Sonata GridPanel, modelled (simplified) like this:
~~~~~~~~~~~~~~~
Name | Type | Blob
~~~~~~~~~~~~~~~
Boby | Aaaa | Bbbb
John | Cccc | Xxxx
Let assume the column Blob is a custom column I made which you can click on.
It is controlled by a custom twig.
My custom twig is like this
{% extends stuff %}
{% block field%}
<div class="opener">
<img
src="{{ asset('bundles/bobby/images/map_magnify.png') }}"
width="30"
height="30"
style="cursor:pointer;"
onclick="createPopUp('{{ admin.id(object) }}');"
>
</div>
{% endblock %}
As you can see, I pass the {{ admin.id(object) }} as a parameters of the function, so the function in my JS file will be aware of the value returned by the parameters.
For example, according to my grid there and assuming the ID of my object is the column Name, if I click on Bbbb, the {{ admin.id(object) }} will return Boby as a value.
This is working.
Now, I want to do quite the same thing, but not returns the ID of a whole object, but a specific value of an object.
Still according to my example, if I click on Bbbb, I would like to retrieve the value contained in the column Type for this object. The value should be then Aaaa.
But I don't know how to do this.
I tried to pass this {{ block('field') }}, but it does not target a specific column. How can I select the block by it's name.
I'm not familiar enough with twig and I'm quite lost looking inside all the Sonata's twig files.
How could I do this ?
You'll have to know to that in my case, the value I want to retrieve is "controlled" by a Sonata's Twig, and not by my custom twig.
I think you can do this using object var from the template:
{% extends stuff %}
{% block field%}
<div class="opener">
<img
src="{{ asset('bundles/bobby/images/map_magnify.png') }}"
width="30"
height="30"
style="cursor:pointer;"
onclick="createPopUp('{{ object.type }}');"
>
</div>
{% endblock %}
Take a look at row templates from sonata admin documentation for more informations

Resources