Skip to content

diit/Json-Decode-Twig

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 

JSON Decode Twig Filter for Craft CMS

Adds a json_decode filter to your toolkit.

Example Use

Add extra data to fields like multiselect, in this example add icons from multiple sources.

{{ forms.multiselect({
	label: "Example Icons"|t,
	id: 'icons',
	name: 'icons',
	value: example.icons,
	errors: example.getErrors('icons'),
	required: true,
	options: [
		{
			label: 'Camping',
			value: '{ "type":"svg", "class":"camping" }'
		},{
			label: 'Adventure',
			value: '{ "type":"maki", "class":"maki-pitch" }'
		},{
			label: 'Beach',
			value: '{ "type":"maki", "class":"maki-swimming" }'
		},{
			label: 'Mountain',
			value: '{ "type":"svg", "class":"mountain" }'
		}
	]
}) }}
<div class="example__icons">
	{% for rawicon in examplePlugin.icons %}
	{% set icon = rawicon | json_decode %}
	{% if icon.type == 'maki' %}
	<span class="{{ icon.class }}"></span>
	{% elseif icon.type == 'svg' %}
	{{ SVGicons.outdoor(icon.class) }}
	{% endif %}
	{% endfor %}
</div>

Options

By default json_decode outputs an object but you can also output an associative array by passing true as a parameter value to the filter.

{% set icon = rawicon | json_decode(true)  %} 

Dale Inverarity © 2015 - All rights reserved

About

Adds a json_decode filter to your craft CMS site.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages