Git Product home page Git Product logo

craft-query-strings's Introduction

Craft Query Strings

A Craft CMS plugin to provide twig filters and functions to help with query string management. This is especially helpful for adding query strings back to pagination.

version 1.0.7

preserveQueryStrings

The Preserve Query String filter allows you to add |preserveQueryStrings to any URL output in twig, and it will keep the query strings as they should appear in the URL.

E.g.

{% if pageInfo.prevUrl %}<a href="{{ pageInfo.prevUrl|preserveQueryStrings }}">Previous Page</a>{% endif %}
{% if pageInfo.nextUrl %}<a href="{{ pageInfo.nextUrl|preserveQueryStrings }}">Next Page</a>{% endif %}

getQueryStrings

Pull an array of query strings from Craft. This gets around the problem of duplicated query string keys being lost, turning them into an array you can loop through.

An array will be returned with objects. Use .key and .value.

Return all URL queries

{% for query in getQueryStrings() %}
  {{ query.key }} - {{ query.value }}
{% endfor %}

Return only URL queries that match a key

{% for query in getQueryStrings('lookForKey') %}
  {{ query.key }} - {{ query.value }}
{% endfor %}

getQueryFormFields

Sometimes you want to use query fields in a form, to preserve these values you can use the following in your templates.

{{ getQueryFormFields() }}

which is shorthand/equivalent to:

{% for query in getQueryStrings() %}
  <input type="hidden" name="{{ query.key }}" value="{{ query.value }}">
{% endfor %}

craft-query-strings's People

Contributors

billythekid avatar mrnebbi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

craft-query-strings's Issues

Missing value throws a plugin error

Code assumes there will always be a key and value. Need to change this to perform a check.
$queryObject = (object) ['key' => $querySplit[0],'value' => $querySplit[1]];

Craft 4

Will Craft 4 support be added ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.