Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Help needed with adding a class to p.url from a page collection

Started by Matthew Randle 7 years ago · 2 replies · 1047 views
7 years ago

Hi all, I am a newbie with Grav (and Twig) and have what is perhaps a daft question so apologies in advance.

I've been learning bit by bit and have a healthy enough starting point with this collection...

{% for p in page.collection.order('folder','asc') %}
###{{ p.title }}
{% set showcase_image = p.media.images|first.cropZoom(450,200) %}
[{{ showcase_image.html(p.title,p.title) }}]({{ p.url }})
{{p.summary(250)}}
[Find out more]({{ p.url }})
{% endfor %}

However, I want to add a class to p.url

I've tried a few things including appending this ?classes=button,big to {{p.url}} but nothing works.

Can someone please help me out/ point me in the right direction? Any help would be much appreciated

7 years ago

Where are you adding that code?

Twig is mainly for templating, perhaps you don't need markdown syntax just use twig and html:

TWIG
{% for p in page.collection.order(‘folder’,‘asc’) %}
    <h3>{{ p.title }}</h3>
    {% set showcase_image = p.media.images|first.cropZoom(450,200) %}
    <a href="{{ p.url }}">
        <img src="showcase_image.url" alt="{{p.title}}" />
    </a>
    {{ p.summary(250) }}
    <a href="{{ p.url }}">Find out more</a>
{% endfor %}

Suggested topics

Topic Participants Replies Views Activity
Support · by Anna, 4 days ago
1 93 4 days ago
Support · by Anna, 3 weeks ago
1 265 3 weeks ago
Support · by webmasterodp, 1 month ago
4 380 1 month ago
Support · by nwhitfield, 1 month ago
2 351 1 month ago
Support · by stell, 2 months ago
5 657 1 month ago