Pro Tip: Use Views ShortCode Attributes

Toolset has an extremely powerful feature, where you can pass any ShortCode attribute to a View ShortCode, and listen to the value passed in that attribute while in the Loop of the View.

For example, you might want to re-use the same View in several places on your website, displaying the same (or different) content all over again, however with distinct style.
Instead of using a bunch of Conditional ShortCodes in the View, you could simply insert the View and pass a ShortCode attribute style to it, like so [wpv-view name="my-view" style="style--modifier"].

Every time you insert the View in a new place, and want to have a different Style, you would alter the style attribute value.

Then, in the View, you would use classes to style your HTML, and pass the dynamic Style Modifier to those classes like so class="my-class-[wpv-attribute name='style']"

This will now create HTML classes in each View loop output with a modifier corresponding to the value you passed to the style attribute when you inserted the View.

Thus, you can now create CSS, that addresses all my-class-{modifier} cases, and do not need to use Conditional ShortCodes to alter the style in the loop.

The possibilities with Views ShortCode attributes are almost infinite. You can define almost anything in a ShortCode attribute and later listen to it in the View loop.

It helps a lot to avoid creating several views over and over again just to alter tiny details in the loop.

1 Like