New: Learn Statamic on Laracasts!

We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

calling partial and pass a variable: possible?

Peter Emil van den Berg April 22, 2020 by Peter Emil van den Berg

Hi there! For images I use glide and want to re-use a partial. This partial covers the backgroundimage portion for several instances. I use it for hero images on pages (big & in your face) and for overviews with lists of several items (same asset, now used small). In essence it goes like this: a template...

{{ asset:hero_image }}
<div class="img-wrapper">
  <div class="img--focus" style="{{ partial:backgroundimage-focus }}"></div>
{{ /asset:hero_image }}

... calls the partial which covers the backgroundimage part:

background-image: url({{ glide:url }}); background-position: {{ focus_css }};

Now I like to pass in a variable in the first template, like thumb which then is put to use in the partial to do some glide stuff like the width:

background-image: url({{ glide:url width='500' }}); background-position: {{ focus_css }};

Question: can I pass in a variable or conditional so I can re-use the partial instead of creating a second - almost identical - partial just to cover the width=500 part?

Answered by Duncan McClean!
>>>>>>> Answered <<<<<<<
2 Replies