Skip to content

diit/Json-Decode-Twig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

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