Any way to add a css class when calling a snippet?

I’m adding testimonial snippets here and there, and they all need to be different css classes. Any way to add a css class when calling a snippet?

For example, can we do something like:
<?php snippet('testimonial') addclass('med--col-4) ?>
?

You can pass variables to a snippet like this …

<?php snippet('testimonial', array('class' => 'med--col-4')); ?>

And then you can use $class in your snippet template.

https://getkirby.com/docs/templates/snippets#passing-variables-to-snippets

1 Like

Nice!

You mean like:
<?php snippet('testimonial', array('class' => $class'')); ?>

You can do that if you have defined $class before, otherwise, pass a string like @flokosiol suggested.

1 Like

If $class is already defined, you can even do this:

<?php snippet('testimonial', compact('class')); ?>

It means the same as:

<?php snippet('testimonial', array('class' => $class)); ?>
1 Like