Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

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

Started by Matthew Randle 7 years ago · 2 replies · 611 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 Thomas, 1 week ago
2 50 6 hours ago
Support · by Anna, 2 days ago
2 58 9 hours ago
Support · by Justin Young, 10 hours ago
1 28 10 hours ago
Support · by Duc , 1 week ago
2 63 5 days ago
Support · by Colin Hume, 1 week ago
2 53 5 days ago