Developer Docs
  • Getting started
  • Tutorials
    • Integrate your theme with HivePress
    • Create a custom HivePress extension
  • Framework
    • Blocks
      • Callback
      • Container
      • Content
      • Form
      • Menu
      • Modal
      • Part
      • Section
      • Template
      • Toggle
    • Components
      • Cache
      • Helper
      • Request
      • Router
      • Translator
    • Configurations
      • Comment types
      • Image sizes
      • Meta boxes
      • Post types
      • Scripts
      • Settings
      • Strings
      • Styles
      • Taxonomies
    • Controllers
    • Emails
    • Fields
      • Checkbox
      • Checkboxes
      • Date
      • Date Range
      • Email
      • File
      • Number
      • Number Range
      • Password
      • Phone
      • Radio Buttons
      • Repeater
      • Select
      • Text
      • Textarea
      • Time
      • URL
    • Forms
    • Menus
    • Models
      • Making queries
      • Creating models
      • Customizing models
    • Templates
  • Resources
    • Code snippets
    • Code reference
    • Hook reference
    • REST API
Powered by GitBook
On this page
  • Parameters
  • Example

Was this helpful?

  1. Framework
  2. Blocks

Toggle

PreviousTemplateNextComponents

Last updated 2 years ago

Was this helpful?

This block type renders a toggle link that sends an AJAX request on every subsequent click, changing its icon and label depending on the current state.

Parameters

  • view - the link view, set to icon if labels are not required;

  • url - the URL for sending AJAX requests on click;

  • states - an array of the link state parameters;

  • attributes - the link HTML attributes;

  • active - true if the toggle link is currently active.

Example

The code below renders a toggle link that displays the "Follow" text with the user-plus icon when inactive and the "Unfollow" text with the user-minus icon when active. It sends an AJAX request to the https://example.com URL, changing the link icon and label on every subsequent click.

echo ( new HivePress\Blocks\Toggle(
	[
		'url'    => 'https://example.com',

		'states' => [
			[
				'icon'    => 'user-plus',
				'caption' => 'Follow',
			],
			[
				'icon'    => 'user-minus',
				'caption' => 'Unfollow',
			],
		],
	]
) )->render();
Font Awesome