Navigation menu list in Grav - grav

I am new to Grav and I am trying to get the basics.
If I want the following page structure:
root
|_______ set1
| |___ page_10
| |___ page_11
| |___ page_12
|
|_______ set2
| |___ page_20
| |___ page_21
...
How can I make set1 display a regular navigation menu with links to each inner page?
Something like:
- Page 10
- Page 11
- Page 12
Where each entry is an html link to each page.

You can do that with twig with something like this:
{% for childpage in page.header.children %}
{{ childpage.title}}
{% endfor %}
This iterate through all the children of your page, and display a link and the page title.

Related

how to generate manually a route to easyadmin

I'm using easyadmin for my website. In order to manage a gallery of images I would like to display a thumbnail of each one of them wrapped in a link that lead to the actual show action of the entity Image
here is the definition of the gallery :
Album:
class: App\Entity\Album
list:
fields:
- titre
- images
show:
fields:
- titre
- { property: images, template: admin/field_mosaic.html.twig }
And the custom template I have created :
<div class="gallery m-2">
{% for image in item.images %}
<a href="{{ path('easy_admin_bundle') }}?entity={{ link_parameters.entity }}&action={{ link_parameters.action }}&primary_key_name={{ link_parameters.primary_key_name }}&id={{ item.id }}">
<img class="rounded m-2" src="{{ asset(vich_uploader_asset(image, "imageFile"))|imagine_filter('profile_list') }}" alt="image #{{ loop.index }}">
</a>
{% endfor %}
</div>
Unfortunately I don't know the name of the main route of the easyadminbundle. I tried {{ path('admin') }}which doesn't worked and the name in the routes\easy_admin.yaml file which doesn't work either.
Where can I found it ?
After 10 min I decided to run a simple
$php bin/console debug:router
And I found this little one:
+--------------+------------------------------------------------------------------------------------------+
| Property | Value |
+--------------+------------------------------------------------------------------------------------------+
| Route Name | easyadmin |
| Path | /admindatabase/ |
| Path Regex | #^/admindatabase/$#sD |
| Host | ANY |
| Host Regex | |
| Scheme | ANY |
| Method | ANY |
| Requirements | NO CUSTOM |
| Class | Symfony\Component\Routing\Route |
| Defaults | _controller: EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController::indexAction |
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
+--------------+------------------------------------------------------------------------------------------+
Sorry for bothering....

how to only show number with truncate or css

I want to display S1 only instead of season 1. Thus I need to truncate season and put only 1 and add "S" at the front.
<a href="{% url 'season_detail' slug=all_episode.season.slug %}">
{{ all_episode.season}}
</a>
How do I truncate the word "season"?
Edit:
Here's what I did again
I created templatetag folder inside my app
then added init.py and seasonify.py
and inside seasonify.py I added
from django import template
register = template.Library()
#register.filter
def seasonify(value):
return value.replace('season', 'S')
then inside my template
I added
{% load seasonify %}
and {% episode.season|seasonify %}
Your best bet is to write a custom template filter. The logic is simple:
#register.filter
def seasonify(value):
return value.replace('season', 'S')
then simply use it in your templates:
{{ all_episode.season | seasonify }}
See Django docs for details on where to put this code.

for in twig templates of drupal is behaving strangely

I am trying to show only upcoming events from a list of events. Below is how I have tried to display.
<div class="row">
{% for item in items %}
{% if item.content['#node'].field_event_type.getValue()|first.value == 'upcoming' %}
<div class="col">{{item.content}}</div>
{% endif %}
{% endfor %}
</div>
But the output rendering is, the second event is displaying after the row div like below. I don't understand how this is happening as the for loop is inside the row div
<div class="row">
<div class="col"> content </div>
</div><div class="col"> content </div>
Expected output
<div class="row">
<div class="col"> content </div>
<div class="col"> content </div>
</div>
Twig does lots of things:
loading (open your Twig content)
parsing (create a parse tree from your Twig content)
compiling (browse that tree to create a php file)
caching (store the php file somewhere to avoid recompile it next time)
executing (execute the generated php file)
When a {% for %} is detected during parsing, Twig calls the token parser recursively until it finds {% endfor %} and builds a token tree. In your case, it would look like:
root
|
--- string
|
--- for
| |
| --- if
| |
| --- string
|
--- string
Then, Twig compiler crosses over that tree recursively and generates the corresponding php code. In that way, the following Twig loop:
{% for i in 1..5 %}
Value = {{ i }}
{% endfor %}
Compiles to this in PHP:
// line 1
$context['_parent'] = $context;
$context['_seq'] = twig_ensure_traversable(range(1, 5));
foreach ($context['_seq'] as $context["_key"] => $context["i"]) {
// line 2
echo "Value = ";
echo twig_escape_filter($this->env, $context["i"], "html", null, true);
}
$_parent = $context['_parent'];
unset($context['_seq'], $context['_iterated'], $context['_key'], $context['i'], $context['_parent'], $context['loop']);
$context = array_intersect_key($context, $_parent) + $_parent;
As you can see, a {% for %} is no more than a simple foreach and as Twig tokens are stored into a tree, it is by design not possible to display contents located below a pair of open/close tags.
The only possibility I can see is that one of the tag you're using in Twig is playing with output buffering, and one of the methods you're using in your loop breaks the ob stack (like a ob_get_clean() without any ob_start() for example, that have been open previously).
My advice is to grep your twig file name into your cache directory (eg: grep -Ri 'test.twig' cache/) in order to see that file compiled to PHP, to understand exactly what it does, and debug it.
Instead of filtering your content in twig, filter the results in your Drupal view.
In the "filter criteria" on your view, select the field_event_type field and set it "is equal to" and select/add 'upcoming' as the option.
If you filter in the view, you don't have to mess with the twig template.

Create a link in Twig with translate filter

I'm trying to create an email link with only Twig tags. I've read numerous posts here but I can't get this one working! The problem I'm facing is that a string must get a translate filter in it.
The link itself is for email purpose.
So what I try to make is a link like this:
http://www.website.com/service/?subject=1234&message=Desired+amount
So what I tried is this:
{{ ('service?subject=' ~ product.code | url_encode) | url }} // This works perfectly
Now I want to add the &message part, so what I did is this:
{{ ('service?subject=' ~ product.code ~ '&message=' ~ (Desired amount | t) | url_encode) | url }}
As you can see the Desired amount needs to have a translate tag (which is t by the way).
Offcourse this doesn't work.
Does anybody know how to create such link with a filter in it?
I'm really pulling my hair out right now :(
Something like this:
configure a route:
# example
acme_demo_service:
path: /service
defaults:
_controller: AcmeDemoBundle:Test:service
Use url function:
{% set link = url('acme_demo_service', {'subject':product.code, 'message':'Desired amount'|trans}) %}
{{ link }}

Liquid and Jekyll - Add CSS class on occurence of character in an array

on my site i have lists using two different kinds of styles for list items. Their occurance is uneven.
For now i edit these lists manually in html. I would like to put them inside an array in the YAML front matter and let jekyll generate the appropriate lists.
Example:
My idea is to put all list items in an array in the YAML front matter and tag those, which should be italic, with a string like 'ITALIC_':
list: [ITALIC_Main, 300g tomatoes, 1 mozzarella ball, ITALIC_Dressing, olive oil, vinegar, ...]
Is it possible to check not only the array for a certain string but
the array items too?
How can i filter the tagged array items and apply a certain css class via Jekyll?
Thanks for your help!
Vin
I think you have a modeling problem ;-) You're mixing datas and style : No Goood !
I propose a more dissociated solution, with organized datas on one place and presentation in an other.
It can be something like this :
---
title: recipe
layout: default
recipe:
ingredients:
main:
- ingredient1
- ingredient2
dressing:
- ingredient3
- ingredient4
optional:
- ingredient5
operations:
.... To be continued ...
---
<h2>Ingredients</h2>
{% for part in page.recipe.ingredients %}
<h3>{{ part[0] }}</h3>
<ul>
{% for ingredient in part[1] %}
<li>{{ ingredient }}</li>
{% endfor %}
</ul>
{% endfor %}
<h2>Operations</h2>
{% for part in page.recipe.operations %}
To be continued ...
(Not tested) You can write it as: ITALIC_Main_ and in the template loop just remove the ITALIC with
{{ site.list.item | remove_first: "ITALIC" }} - this will leave you with _Main_ which is converted to italic style in markdown.

Resources