Hot answers tagged

5

You can combine multiple relationship criteria by passing an array to the relatedTo parameter with the keyword 'and' or 'or' as the first array element. You want your entries to be related to any of the tags, so this should work for you: {% set query = craft.request.getQuery() %} {# Make sure selectedTagIds is an array #} {% set selectedTagIds = query.tags ...


4

Although it is (as of today) not yet documented, looking through the redirect twig extension revealed that the redirect tag can accept a second parameter for the http status code. So forcing a 301 is done as follows: {% redirect 'pricing' 301 %} I've sent a request to P&T to add this to the docs.


4

If an attribute is set to true, it will get added without a value. {{ tag('input', { id: idVar, name: nameVar, required: true }) }} Also, if it is set to null or false, it will be omitted, as if it was never listed in the first place.


3

Update. After looking at the tag model a little more closely, it looks like tags have both a title and slug — so if you use the slug to construct your url then you shouldn't have that problem. For your tag index: <ul> {% for tag in craft.tags.order('title') %} <li><a href="{{ siteUrl }}tags/{{ tag.slug }}">{{ tag.title }}</...


3

You could try something like following reducing the tagged entries into IDs that you then filter against (see this thread): {% set tag = craft.tags.search('All-Stars').first() %} {% set allEntries = craft.entries.section('news') %} {% set taggedEntries = craft.entries.section('news').relatedTo(tag).ids %} {% set omitIds = 'and, not ' ~ taggedEntries|join(', ...


2

Assuming you want the first category that's selected in the field, you'd set your "Entry URL Format" setting to: {categoryFieldHandle.first().slug} You can access any of your custom fields by their handle in a similar way.


2

For your link, change {{ tag.title | kebab}} to {{ tag.slug }} Then on your tag.html page change your tag variable to this: {% set tag = craft.tags.slug( craft.request.segment(2) ).first() %} This is how I have it set up and works fine. Edit: Forgot the route needed: Add this to your routes.php: 'tags/{slug}' => 'tags/tag',


2

I think what you are trying to achieve here has little to do with the actual templating itself. You can add your tags as data-attributes like so {% set entries = craft.entries.section('yoursection') %} <ul> {% for entry in entries %) <li data-tag={% for tags in entry.tagsFieldHandle %){{tag.title}}{% endfor %}>{{entry.title}}</li> {% ...


2

Not really (or not without a custom solution anyway) — tags are designed to be added by anyone. You might be better off using categories for this, which you can resist access to via userGroup permissions.


1

As pointed out in the comments to your question, there's no need to specify the locale with your relatedTo parameter. I already wrote you in response to your other question, Craft always works in one locale only if you don't explicitly make it to do otherwise. {% for entry in entries %} <h3>{{ entry.title }}</h3> {% for tag in craft....


Only top voted, non community-wiki answers of a minimum length are eligible