Hot answers tagged

6

Try using this (completely untested): {% if paginate.prevUrl %} <a href="{{ paginate.prevUrl }}?{{ craft.request.getQueryStringWithoutPath() }}">Previous Page</a> {% endif %} {% if paginate.nextUrl %} <a href="{{ paginate.nextUrl }}?{{ craft.request.getQueryStringWithoutPath() }}">Next Page</a> {% endif %} Update: The ...


6

Use craft.request.getQueryStringWithoutPath() like so: products/category?{{craft.request.getQueryStringWithoutPath()}} Returns the query string, except for the p= param (which was probably added by your .htaccess redirect). More complicated logic to avoid the ? when the query string is empty (one of several ways to do this): {# queryString will include ...


5

This is a longer version answer (code wise) to the one Douglas already posted. He did a very nice job of explaining how to get a URL parameter and what to pay attention to handling the results. I will try to show you how to build a query from multiple unknown params, so any of these combinations is possible and potentially return a single (and unique) Entry ...


5

You can access 'post' or 'get' parameters using craft.request.getParam('param'); and then use them to retrieve the corresponding entry. So, given the URL: http://example.com/subsection/filename.html?id="170" In your template, you would grab the param 'id', and use it to retrieve the entry. {% set entryId = craft.request.getParam('id') %} {% set entry = ...


5

Untested, but something like this should work: {# set base criteria #} {% set params = { section: 'productsServices', limit: null } %} {# set relationship criteria #} {% set relationParam = ['and'] %} {% for segment in craft.request.segments %} {% if loop.index != 1 and segment != 'all' %} {% set category = craft.categories.slug(segment)...


4

Instead of using the chained syntax, you should build a parameter object and pass that in to craft.entries, like so: {# Get a start date value from the URL (my use case) #} {% set start_date = craft.request.getSegment(3) %} {# e.g. '2015-12-10' #} {# Create a parameter object, with default values #} {% set params = { section: 'events' } %} {# If ...


3

The query value for p has been the pageTrigger since Craft 1.0 (and probably in the beta as well). I'm not sure why you were still able to use it for other purposes up until recently. To be honest, it sounds like you were accidentally exploiting a bug, which has since been fixed.


3

Your syntax is a bit off – the search() parameter doesn't accept multiple parameters, only a search query (e.g. .search('body:foobar')) or an object containing the search query plus search term options. In your case, you're actually passing an object (.search(entry.clientsOrAgency)), in which case Craft will look for a query parameter on that object (the ...


3

It is passed as a parameter to your function public function actionView($post_id){ Craft::dd($post_id); } Note: your parameter must have the same name like defined in your route. You can't access it with public function actionView($postId)


3

The behaviour you're seeing is by design – craft.request.getQuery() will return all GET variables if it's called without arguments, whereas craft.request.getParam() requires the name argument – i.e. craft.request.getParam('foo'). The changelog notes for build 1.3.2465 does reference a couple of issues related to these methods, but nothing suggesting any ...


3

You’re just missing the : at the end of :notempty: in your second example. This will work: {% set params = { section: 'sectionName', customField: ':notempty:', limit: 10} %}


3

The client must have added a new rule which was causing the problem. changed from RewriteRule (.+) index.php?p=$1 [L] to RewriteRule (.+) index.php [L] Not exactly sure why they added that but...


2

The only possible core solution to query for these entries in Twig is to query for entry IDs first, process them with merge or without and then pass the IDs to the id parameter of a new ElementCriteriaModel. Other than your solution implementing a conditional in the for loop this works with paginate and getNext tags, you only query for the entry models you'...


2

You are currently passing a string '>= pers' to the array. Change this to: '>= ' ~ pers This "concatenates" the string '>= ' and the value of your pers variable (converted to a string).


2

If you want to explicitly grab them from PHP, this should also work: $result = Craft::$app->getRequest()->resolve(); From there, you could grab $result[1], which should be an array: array( 'variables' => array( 'post_id' => 3, , 'template' => 'post-entry', 'p' => 'post/3', )


1

Here's something I've got for filtering news by author and by category. You might be able to re-work it for your needs? From a page URL being: http://project.com/news?&cat=CATEGORY&author=NAME {% set query = {} %} {% set categoryParam = craft.app.request.getParam('cat') %} {% set authorParam = craft.app.request.getParam('author') %} {% set ...


1

This should take care of it: {% set stage = craft.request.getParam('stage') %} {# check if stage is an array #} {% if stage is iterable %} {% for stageItem in stage %} {# make sure stageItem has content #} {% if stageItem is not empty %} {{ stageItem }} {# would output the selected stage.value #} {% ...


1

I think the answer you’re looking for is here. TL;DR: relatedTo method accepts a CategoryModel, not the title(slug) of a category.


1

This should do what you're looking for: {% set someEntries = craft.entries({ level: 1, id: '1,2,3,4,5', myOtherField: 'and, not blue, not green' }) %}


1

Based on your example and description, it's a bit hard to tell whether you are dealing with a category template or an entry template, because in your description you say that the category handle is called 'media', but in the example you are grabbing entries in the section called 'media'. Assuming you are on a category template (i.e. trying to create a ...


1

You need to get each parameter from the URL separately and repeat the steps you already did for "collection": Get search parameters from the URL query string Find categories that match the slugs in your query string And merge them into the relationParam array.


1

Hmm, I can't think of how you would do this in Twig. But you may want to jump into PHP and perform your query a little more manually... This answer provides a few good ways to do that. Specifically, I'd take a look into either a custom variable or a template hook. I'm personally a huge fan of the template hook... it feels like unlimited power in a tiny ...


1

I don't think you're going to be able to do what you're looking for purely through Twig. You can, however, write a plugin that either uses a service and variable or a Template Hook, so you can drop down to the PHP level and use DbCommand's where to apply your extra date conditionals to your SQL query directly.


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