Is there a simple timber way of using WP's do_shortcode?
I currently use: which does exactly what I need, but cant find anything as concise in timber - Don't need to change/filter anything, just need to show the shortcode in theme template rather than WP editor.
Thanks.
{{ function('do_shortcode', 'content') }}
Thanks so much.
How do I pass post.id inside a shortcode function?
As in:
{{ function('do_shortcode', '[favorite_button post_id="{{post.id}}"]') }}
@grohlbainselic You can鈥檛 nest the double curly braces {{ }}. But, you could use Twig鈥檚 string concatenation with ~.
{{ function('do_shortcode', '[favorite_button post_id="' ~ post.id ~ '"]') }}
Sometimes that gets a little difficult to read with all the " and '. As an alternative, you could also use the format filter in Twig, which works pretty much like sprintf in PHP and replaces all the placeholders in your string with what you pass to the filter.
{{ function('do_shortcode', '[favorite_button post_id="%s"]'|format(post.id)) }}
Most helpful comment
{{ function('do_shortcode', 'content') }}