tonik / theme

Tonik is a WordPress Starter Theme which aims to modernize, organize and enhance some aspects of WordPress theme development.
http://labs.tonik.pl/theme/
MIT License
1.33k stars 140 forks source link

Pass array in template #77

Closed multiplehats closed 5 years ago

multiplehats commented 6 years ago

Hey,

Love Tonik :)

Noobie question.

Let's say I have a button template like so:

<button class="<?php echo $button_classes ?>"><?php echo $title ?></button>

And I want to render that button:

template('partials/button', [ 'title' => 'Click me' ]);

How can I send an array to render the button classes? I tried a few things already.

template('partials/button', [ 'title' => 'Click me', 'button_classes' => array('thing1', thing2') ]);

Thanks!

msacchetti commented 6 years ago

You just need to either access the array values directly or more likely loop through them.

Directly $button_classes[0] $button_classes[1]

Loop foreach ($button_classes as $class) { echo $class;)